#include "MissionManager.h"
#include "Character/Player.h"
#include "Character/monster/Monster.h"
#include "Character/Part.h"
#include "Script/ScriptMgr.h"
#include "Character/PlayerMgr.h"
#include "Character/drop/DropMgr.h"
#include "Character/HuoYueDuPart.h"
#include "Common/TableData/ConstantConstantCfg.h"
#include "Common/TableData/TaskdynamicTaskCfg.h"
#include "Common/TableData/TaskcontentComcondCfg.h"
#include "Common/TableData/MapMapCfg.h"
#include "Common/TableDataEx/MapCfg.h"
#include "Effect/EffectMgr.h"
#include "Common/TableData/MonsterMonsterCfg.h"
#include "Common/TableData/DropDropCfg.h"
#include "Common/TableData/BoxDropCfg.h"
#include "Common/TableData/DuplicateDuplicateCfg.h"
#include "Common/TableData/SkillBuffCfg.h"
#include "Common/TableData/AnswerAnswerCfg.h"
#include "Common/TableData/AreaAreaCfg.h"
#include "Common/TableData/TasktypeTasktypeCfg.h"
#include "Character/monster/MonsterRefCfg.h"
#include "Common/TableData/NpcNpcCfg.h"
#include "Common/TableData/AreaAreaCfg.h"
#include "Common/TableDataEx/DeputyCfg.h"
#include "Common/TableData/ItemItemCfg.h"
#include "Common/TableData/BoxDropCfg.h"
#include "Common/TableData/ButtonButtonCfg.h"
#include "Common/CampDefine.h"
#include "Common/TableDataEx/DropCfg.h"
#include "Common/TableData/TaskcontentTextCfg.h"
#include "Common/TableData/RoleExpCfg.h"
#include "Common/TableData/ThingCollectCfg.h"
#include "Character/PvpPart.h"
#include "Common/PackageDefine.h"
#include "Character/GodPart.h"
#include "Character/SkillPart.h"
#include "Common/TableData/ChoiceChoiceCfg.h"
#include "Common/TableData/TasktrackerFirstChapterCfg.h"
#include "PlaneMgr/PlaneMgr.h"
#include "PlaneMgr/CPlane.h"
#include "Character/DeputyPart.h"
#include "Character/GodPart.h"
#include "Character/OperateLimitPart.h"
#include "Common/Utility/TimeUtility.h"
#include "Common/TableDataEx/OperateCfg.h"
#include "ServerModule/LogicActivityModule.h"
#include "Common/TableDataEx/DuplicateCfg.h"

MissionManager::MissionManager()
{
	_missionInfoMap.clear();
	_dymissionTextMap.clear();
	_dymissionInfoMap.clear();
	_dycondtionInfoMap.clear();
	_missionChapterMap.clear();
	_postList.clear();
	_withoutPreConMissionsList.clear();
	_tabal.clear();
	_triggerHuoyue.clear();
	_dymissionTypeMap.clear();
	_setAllMissionType.clear();
	_mapOptionMission.clear();
	_mapBelongOption.clear();

	m_mapMapNpcParam.clear();
	m_mapMapMonsParam.clear();
	m_mapMapAreaParam.clear();
	m_mapMapCollectThingParam.clear();
	m_mapMapUseThingParam.clear();
	m_mapLevItem.clear();
	m_setDyMap.clear();
	m_mapAreaToClientCollect.clear();
	m_mapMonsToBox.clear();
	m_mapAreaToButton.clear();
	m_mapCollectToBox.clear();
	m_mapMissionTypeLevItem.clear();
	m_mapMapCollectAreaParam.clear();
	m_mapMapButtonAreaParam.clear();
	m_setAllArea.clear();
	m_mapNoMapMonsParam.clear();
	m_mapMissionTypeLevItemNum.clear();
	m_mapLevEquip.clear();

	m_BountyFreshItemID = 0;
	m_BountyMaxAcceptNum = 0;
}

MissionManager::~MissionManager()
{
	
}

bool MissionManager::Init()
{
	//
	m_pMissionInfoPool = new ObjectPool<MissionInfo>();
	MMO_ASSERT(nullptr != m_pMissionInfoPool);

	m_pMissionTrackPool = new ObjectPool<MissionTrack>();
	MMO_ASSERT(nullptr != m_pMissionTrackPool);


	//初始化所有的任务类型
	_setAllMissionType.insert(MISSION_TYPE_ID_TRUNK);
	_setAllMissionType.insert(MISSION_TYPE_ID_BRANCH);
	_setAllMissionType.insert(MISSION_TYPE_ID_OTHER);
	_setAllMissionType.insert(MISSION_TYPE_ID_BANISH);	
	_setAllMissionType.insert(MISSION_TYPE_ID_LOOP);
	_setAllMissionType.insert(MISSION_TYPE_ID_BOUNTY);
	_setAllMissionType.insert(MISSION_TYPE_ID_CAMP);
	_setAllMissionType.insert(MISSION_TYPE_ID_GUILD);
	_setAllMissionType.insert(MISSION_TYPE_ID_TREASURE);
	_setAllMissionType.insert(MISSION_TYPE_ID_GUILD_DAILY);
	_setAllMissionType.insert(MISSION_TYPE_ID_DEPUTY_COLLECT);
	_setAllMissionType.insert(MISSION_TYPE_ID_ACT_COLLECT);
	_setAllMissionType.insert(MISSION_TYPE_ID_DAILY);

	//任务章节表
	if (!LoadChapter("./data/csv/taskchapter.csv"))
	{
		return false;
	}
	//初始化任务基础表
	if (!LoadConfig("./data/csv/task.csv"))
	{
		return false;
	}
	if (!ProcessDyCondition())
	{
		return false;
	}
	if (!ProcessDyMission())
	{
		return false;
	}
	if (!ProcessDyText())
	{
		return false;
	}
	if (!ProcessItemData())
	{
		return false;
	}
	if (!ProcessEquipData())
	{
		return false;
	}
	if (!ProcessMapData())
	{
		return false;
	}
	if (!ProcessBoxData())
	{
		return false;
	}
	if (!ProcessButtonData()) //要放到 ProcessMapData 后面
	{
		return false;
	}


	const ConstantConstantCfgInfo *pBountyFreshItemCfg = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_BountyFreshItemID);
	if (nullptr == pBountyFreshItemCfg)
	{
		LogErrFmtPrint("[logic] MissionManager::Init...nullptr == pBountyFreshItemCfg...id:%d ", EArg_BountyFreshItemID);
		return false;
	}

	const ConstantConstantCfgInfo *pBountyMaxAcceptCfg = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_BountyMaxAcceptNum);
	if (nullptr == pBountyMaxAcceptCfg)
	{
		LogErrFmtPrint("[logic] MissionManager::Init...nullptr == pBountyMaxAcceptCfg...id:%d ", EArg_BountyMaxAcceptNum);
		return false;
	}

	m_BountyFreshItemID = pBountyFreshItemCfg->constantdata;
	m_BountyMaxAcceptNum = pBountyMaxAcceptCfg->constantdata;
	const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(m_BountyFreshItemID);
	if (nullptr == pItemCfg)
	{
		LogErrFmtPrint("[logic] MissionManager::Init...nullptr == pItemCfg...id:%d ", m_BountyFreshItemID);
		return false;
	}

	if (!CheckFirstChapter())
	{
		return false;
	}

	InitTriggerOut();
	
	return true;
}

bool MissionManager::UnInit()
{
	for (MissionInfoMap::iterator it = _missionInfoMap.begin(); it != _missionInfoMap.end(); ++it)
	{
		MissionInfo* pMissionInfo = it->second;
		if (nullptr != pMissionInfo)
		{
			m_pMissionInfoPool->FreeObj(pMissionInfo);
		}
	}
	_missionInfoMap.clear();
	_dymissionInfoMap.clear();
	_dycondtionInfoMap.clear();
	_dymissionTextMap.clear();
	_missionChapterMap.clear();
	_postList.clear();
	_withoutPreConMissionsList.clear();
	_tabal.clear();

	_triggerHuoyue.clear();
	_dymissionTypeMap.clear();

	m_mapMapNpcParam.clear();
	m_mapMapMonsParam.clear();
	m_mapMapAreaParam.clear();
	m_mapMapCollectThingParam.clear();
	m_mapMapUseThingParam.clear();
	m_mapLevItem.clear();
	m_setDyMap.clear();
	m_mapAreaToClientCollect.clear();
	m_mapMonsToBox.clear();
	m_mapAreaToButton.clear();
	m_mapCollectToBox.clear();
	m_mapMissionTypeLevItem.clear();
	m_mapMapCollectAreaParam.clear();
	m_mapMapButtonAreaParam.clear();
	m_setAllArea.clear();
	m_mapMissionTypeLevItemNum.clear();
	m_mapLevEquip.clear();


	MMO_DELETE(m_pMissionInfoPool);
	MMO_DELETE(m_pMissionTrackPool);
	

	return true;
}

MissionInfo* MissionManager::AllocMissionInfo()
{
	MissionInfo* pMissionInfo = m_pMissionInfoPool->MallocObj();
	return pMissionInfo;
}

MissionTrack* MissionManager::AllocMissionTrack()
{
	MissionTrack* pMissionTrack = m_pMissionTrackPool->MallocObj();
	return pMissionTrack;
}

void MissionManager::FreeMissionTrack(MissionTrack* pMissionTrack)
{
	if (nullptr != pMissionTrack)
	{
		m_pMissionTrackPool->FreeObj(pMissionTrack);
	}
}

bool MissionManager::LoadChapter(const char *szCfgFile) //加载任务章节表
{
	CsvParser reader(3);
	if (reader.LoadFromFile(szCfgFile))
	{
		MMOLOG_FMT_ERROR("[logic] MissionManager::LoadChapter  reader.LoadFromFile is error");
		return false;
	}
	int32_t row = reader.GetHeight();
	int32_t ret = 0;
	char str[1024] = { 0 };
	for (int32_t i = 4; i <= row; ++i)
	{
		MissionChapterInfo info;

		reader.GetInteger(i, "id", 0, &ret);
		info.chapterId = ret;
		ret = 0;

		reader.GetInteger(i, "begin", 0, &ret);
		info.firstMissionId = ret;
		ret = 0;

		reader.GetInteger(i, "type", 0, &ret);
		info.kind = ret;
		ret = 0;

		reader.GetString(i, "tasksubtype", "", str, 1024);
		std::string sOutType = str;
		ParseTaskOutType(info, sOutType);
		memset(str, '\0', sizeof(str));

		reader.GetInteger(i, "savetype", 0, &ret);
		info.recordtype = ret;
		ret = 0;

		reader.GetInteger(i, "lv", 0, &ret);
		info.accept.minLevel = ret;
		ret = 0;


		reader.GetString(i, "comaward", "", str, 1024);
		std::string strFinishReward = str;
		ParseChapterReward(info.chapterId, info.finishAward, strFinishReward);
		memset(str, '\0', sizeof(str));


		reader.GetString(i, "comawardrand", "", str, 1024);
		std::string strFinishRewardRnd = str;
		ParseChapterReward(info.chapterId, info.finishAwardRnd, strFinishRewardRnd);
		memset(str, '\0', sizeof(str));

		reader.GetString(i, "rececond", "", str, 1024);
		std::string strAccept = str;
		if (!ParseChapterCond(info, strAccept))
		{
			return false;
		}
		memset(str, '\0', sizeof(str));

		_missionChapterMap[info.chapterId] = info;
	}

	return true;
}

bool MissionManager::LoadConfig(const char *szCfgFile)
{
	CsvParser reader(3);
	if (reader.LoadFromFile(szCfgFile))
	{
		MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  reader.LoadFromFile is error");
		return false; 
	}

	int32_t row = reader.GetHeight();
	int32_t ret = 0;
	char str[1024] = { 0 };
	
	for (int i = 4; i <= row; ++i)
	{
		MissionInfo* pMissionInfo = AllocMissionInfo();
		if (nullptr == pMissionInfo)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nullptr == pMissionInfo");
			return false;
		}
		reader.GetInteger(i, "id", 0, &ret);
		pMissionInfo->missionId = ret;
		ret = 0;

		reader.GetString(i, "name", "", str, 1024);
		pMissionInfo->name = str;
		memset(str, '\0', sizeof(str));

		reader.GetInteger(i, "truelv", 0, &ret);
		pMissionInfo->progressLev = ret;
		ret = 0;

		reader.GetInteger(i, "chapter", 0, &ret);
		pMissionInfo->chapterId = ret;
		ret = 0;

		const MissionChapterInfo *pChapterCfg = g_GetMissionManager()->GetMissionChapterCfgInfo(pMissionInfo->chapterId);
		if (nullptr == pChapterCfg)
		{
			LogErrFmtPrint("MissionManager::LoadConfig....nullptr == pChapterCfg...missionid:%u, chapterid:%u ", pMissionInfo->missionId, pMissionInfo->chapterId);
			return false;
		}
		//章节下的子任务类型和章节保持一致
		pMissionInfo->kind = pChapterCfg->kind;
		//是否是章节第一个任务
		pMissionInfo->isFirst = (pChapterCfg->firstMissionId == pMissionInfo->missionId);

		reader.GetInteger(i, "failexec", 0, &ret);
		pMissionInfo->failexec = ret;
		ret = 0;

		//接取触发效果
		reader.GetString(i, "receeffect", "", str, 1024);
		std::string receEffect = str;
		ParseTaskReceEffect(pMissionInfo, receEffect);
		memset(str, '\0', sizeof(str));

		//接取任务时发放任务物品
		reader.GetString(i, "receadd", "", str, 1024);
		std::string sReceAdd = str;
		ParseTaskReceAdd(pMissionInfo, sReceAdd);
		memset(str, '\0', sizeof(str));

		//接取任务时扣除任务物品
		reader.GetString(i, "receremove", "", str, 1024);
		std::string sReceremove = str;
		ParseTaskRecereMove(pMissionInfo, sReceremove);
		memset(str, '\0', sizeof(str));
		//完成条件
		reader.GetString(i, "comcond", "", str, 1024);
		std::string sSuccCond = str;
		if (!ParseTaskExecute(pMissionInfo, sSuccCond))
		{
			return false;
		}
		memset(str, '\0', sizeof(str));

		reader.GetInteger(i, "timeoff", 0, &ret);
		pMissionInfo->timeout = ret;
		ret = 0;

		reader.GetString(i, "subeffect", "", str, 1024);
		std::string subEffect = str;
		ParseTaskSubEffect(pMissionInfo, subEffect);
		memset(str, '\0', sizeof(str));

		reader.GetInteger(i, "nexttask", 0, &ret);
		pMissionInfo->backTaskId = ret;
		ret = 0;

		//提交时扣除数据
		reader.GetString(i, "subremove", "", str, 1024);
		std::string sSubRemove = str;
		ParseTaskSubRemove(pMissionInfo, sSubRemove);
		memset(str, '\0', sizeof(str));

		//固定奖励
		reader.GetString(i, "subaward", "", str, 1024);
		std::string sSubAward = str;
		ParseTaskSubAward(pMissionInfo, sSubAward);

		//可选奖励
		reader.GetString(i, "subawardrand", "", str, 1024);
		std::string sSubAwardRand = str;
		ParseTaskSubAwardRand(pMissionInfo, sSubAwardRand);
		memset(str, '\0', sizeof(str));

		if (pMissionInfo->missionId <= 0)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig but pMissionInfo->missionId <= 0:missionId:%d", pMissionInfo->missionId);
			return false;
		}

		if (nullptr != GetMissionCfgInfo(pMissionInfo->missionId))
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig but mission config is exist:%d", pMissionInfo->missionId);
			return false;
		}

		_missionInfoMap[pMissionInfo->missionId] = pMissionInfo;
	}

	MissionListMap mapPost;
	mapPost.clear();
	MAP_UINT32_UINT32 mapNoBackTrunk;
	mapNoBackTrunk.clear();
	//任务配置中统计章节任务数据
	MAP_UINT32_SET_UINT32 mapChapterMission;
	mapChapterMission.clear();
	//构造主线/支线任务关系表
	for (MissionInfoMap::iterator ite = _missionInfoMap.begin(); ite != _missionInfoMap.end(); ++ite)
	{
		if (ite->second->kind != MISSION_TYPE_ID_TRUNK && ite->second->kind != MISSION_TYPE_ID_BRANCH)
		{
			continue;
		}
		//通过后置任务推导前置任务
		if (ite->second->backTaskId > 0)
		{
			MissionInfo *pBackMission = GetMissionCfgInfo(ite->second->backTaskId);
			if (nullptr == pBackMission)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig can not find back task cfg....missionId:%d", ite->second->backTaskId);
				return false;
			}
			if (ite->second->missionId == pBackMission->missionId)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig mission is equal backmission ....missionId:%d,backtaskid:%u ", ite->first, ite->second->backTaskId);
				return false;
			}
			SET_UINT32::iterator iterFind = ite->second->setPreTask.find(ite->first);
			if (iterFind != ite->second->setPreTask.end())
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig mission is equal premission ....missionId:%d,premission:%u ", ite->first, (*iterFind));
				return false;
			}
			//
			pBackMission->setPreTask.insert(ite->first);
			//
			MissionListMap::iterator tempIte = mapPost.find(ite->second->missionId);
			if (tempIte != mapPost.end())
			{
				tempIte->second.insert(ite->second->backTaskId);
			}
			else
			{
				Set mission;
				mission.clear();
				mission.insert(ite->second->backTaskId);
				mapPost.insert(make_pair(ite->second->missionId, mission));
			}
		}
		else
		{
			//后置任务为0 ，并且是属于阵营章节的任务
			if (MISSION_TYPE_ID_TRUNK == ite->second->kind)
			{
				const MissionChapterInfo *pChapterCfg = GetMissionChapterCfgInfo(ite->second->chapterId);
				if (nullptr != pChapterCfg && pChapterCfg->accept.camp > 0)
				{
					mapNoBackTrunk[ite->second->missionId] = ite->second->chapterId;
				}
			}
		}

		if (MISSION_TYPE_ID_TRUNK == ite->second->kind)
		{
			MAP_UINT32_SET_UINT32::iterator iterA = mapChapterMission.find(ite->second->chapterId);
			if (iterA != mapChapterMission.end())
			{
				iterA->second.insert(ite->second->missionId);
			}
			else
			{
				SET_UINT32 setMission;
				setMission.clear();
				setMission.insert(ite->second->missionId);
				mapChapterMission[ite->second->chapterId] = setMission;
			}
		}
	}
	//校验分支任务
	MAP_UINT32_SET_UINT32 mapBelongOption;
	mapBelongOption.clear();
	for (MissionInfoMap::iterator iterOption = _missionInfoMap.begin(); iterOption != _missionInfoMap.end(); ++iterOption)
	{
		MissionInfo *pMissionCfgInfo = iterOption->second;
		if (nullptr == pMissionCfgInfo)
		{
			continue;
		}
		//校验分支条件任务
		/*
		1、分支任务的父任务和子任务必须相同的阵营属性 (去掉)
		2、分支任务的父任务后置任务必须为空
		3、分支任务的子任务前置任务必须为空
		4、分支任务只出现在主支线任务中
		5、分支任务的子任务不允许出现在多个 分支父任务的子任务中，也即一个分支子任务不允许出现在多个分支中
		6、分支任务的父任务和子任务必须属于同一个章节
		*/
		bool optionMission = false;
		SET_INT32 setChoice;
		setChoice.clear();
		std::vector<InterItemPair>::iterator iterCond = pMissionCfgInfo->execute.items.begin();
		for (; iterCond != pMissionCfgInfo->execute.items.end(); ++iterCond)
		{
			InterItemPair &iteminfo = (*iterCond);
			if (MISSION_FINISH_TYPE_OPTION == iteminfo.itemType)
			{
				optionMission = true;
				if (iteminfo.itemId > 0)
				{
					setChoice.insert(iteminfo.itemId);
				}
				if (iteminfo.itemCount > 0)
				{
					setChoice.insert(iteminfo.itemCount);
				}
				if (iteminfo.parma1 > 0)
				{
					setChoice.insert(iteminfo.parma1);
				}
				if (iteminfo.parma2 > 0)
				{
					setChoice.insert(iteminfo.parma2);
				}
				if (iteminfo.parma3 > 0)
				{
					setChoice.insert(iteminfo.parma3);
				}
				break;
			}
		}
		//是分支条件任务
		if (optionMission)
		{
			if (MISSION_TYPE_ID_TRUNK != pMissionCfgInfo->kind
				&& MISSION_TYPE_ID_BRANCH != pMissionCfgInfo->kind
				&& MISSION_TYPE_ID_ADVENTURE != pMissionCfgInfo->kind
				)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  optional mission kind is not trunk or branch or adventure....missionid:%u ", pMissionCfgInfo->missionId);
				return false;
			}
			const MissionChapterInfo *pChapterCfgInfo = GetMissionChapterCfgInfo(pMissionCfgInfo->chapterId);
			if (nullptr == pChapterCfgInfo)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nullptr == pChapterCfgInfo....missionid:%u,chapterid:%u ", pMissionCfgInfo->missionId, pMissionCfgInfo->chapterId);
				return false;
			}
			
			SET_UINT32 setOptionMission;
			setOptionMission.clear();
			if (pMissionCfgInfo->backTaskId > 0)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  optiona mission has back mission....missionid:%u,backmissionid:%u ", pMissionCfgInfo->missionId, pMissionCfgInfo->backTaskId);
				return false;
			}
			SET_INT32::iterator iterChoice = setChoice.begin();
			for (; iterChoice != setChoice.end(); ++iterChoice)
			{
				int32_t choiceId = (*iterChoice);
				const ChoiceChoiceCfgInfo *pChoiceCfg = g_GetChoiceChoiceCfgTable()->GetChoiceChoiceCfgInfo(choiceId);
				if (nullptr == pChoiceCfg)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nullptr == pChoiceCfg....missionid:%u,choiceid:%d ", pMissionCfgInfo->missionId,choiceId);
					return false;
				}
				uint32_t nextMissionId = pChoiceCfg->nexttask;
				const MissionInfo *pNextMissionCfgInfo = GetMissionCfgInfo(nextMissionId);
				if (nullptr == pNextMissionCfgInfo)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nullptr == pNextMissionCfgInfo....nextMissionId:%u,choiceid:%d ", nextMissionId, choiceId);
					return false;
				}
				if (nextMissionId == pMissionCfgInfo->missionId)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nextMissionId == pMissionCfgInfo->missionId....nextMissionId:%u,choiceid:%d ", nextMissionId, choiceId);
					return false;
				}
				if (pNextMissionCfgInfo->setPreTask.size() > 0)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  pNextMissionCfgInfo->setPreTask.size() > 0....missionid:%u,nextMissionId:%u,choiceid:%d ", pMissionCfgInfo->missionId, nextMissionId, choiceId);
					return false;
				}
				const MissionChapterInfo *pNextChapterCfgInfo = GetMissionChapterCfgInfo(pNextMissionCfgInfo->chapterId);
				if (nullptr == pNextChapterCfgInfo)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  nullptr == pNextChapterCfgInfo....missionid:%u nextMissionId:%u,nextMissionChapter:%u,choiceid:%d ", pMissionCfgInfo->missionId, nextMissionId, pNextMissionCfgInfo->chapterId, choiceId);
					return false;
				}
				if (pNextMissionCfgInfo->chapterId != pChapterCfgInfo->chapterId)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  pNextMissionCfgInfo->chapterId != pChapterCfgInfo->chapterId.....option son mission chapter not the same....missionid:%u,chapter:%u,sonmission:%u,sonchapter:%u  ", pMissionCfgInfo->missionId,pMissionCfgInfo->chapterId,pNextMissionCfgInfo->missionId,pNextMissionCfgInfo->chapterId);
					return false;
				}
				setOptionMission.insert(pNextMissionCfgInfo->missionId);
			}
			if (setOptionMission.size() < 1)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  setOptionMission.size() < 1.....option parent mission has no son mission....missionid:%u  ", pMissionCfgInfo->missionId);
				return false;
			}
			MAP_UINT32_SET_UINT32::iterator iterEx = _mapOptionMission.find(pMissionCfgInfo->missionId);
			if (iterEx != _mapOptionMission.end())
			{
				SET_UINT32::iterator iterOptionEx = setOptionMission.begin();
				for (; iterOptionEx != setOptionMission.end(); ++iterOptionEx)
				{
					iterEx->second.insert((*iterOptionEx));
				}
			}
			else
			{
				_mapOptionMission[pMissionCfgInfo->missionId] = setOptionMission;
			}

			SET_UINT32::iterator iterSon = setOptionMission.begin();
			for (; iterSon != setOptionMission.end(); ++iterSon)
			{
				uint32_t sonMissionId = (*iterSon);
				MAP_UINT32_SET_UINT32::iterator iterBelong = mapBelongOption.find(sonMissionId);
				if (iterBelong != mapBelongOption.end())
				{
					iterBelong->second.insert(pMissionCfgInfo->missionId);
				}
				else
				{
					SET_UINT32 setBelong;
					setBelong.clear();
					setBelong.insert(pMissionCfgInfo->missionId);
					mapBelongOption[sonMissionId] = setBelong;
				}
			}
		}
	}

	//校验分支子任务是否属于多个分支任务的子任务
	MAP_UINT32_SET_UINT32::iterator iterBelong = mapBelongOption.begin();
	for (; iterBelong != mapBelongOption.end(); ++iterBelong)
	{
		if (iterBelong->second.size() != 1)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  iterBelong->second.size() != 1.....option son mission belong to more pareng mission...son missionid:%u  ", iterBelong->first);
			return false;
		}
		_mapBelongOption[iterBelong->first] = (*(iterBelong->second.begin()));
	}

	//校验章节表
	MAP_UINT32_UINT32 mapFirstMissionChapter;
	mapFirstMissionChapter.clear();
	MissionChapterInfoMap::iterator iterChapter = _missionChapterMap.begin();
	for (; iterChapter != _missionChapterMap.end(); ++iterChapter)
	{
		MissionChapterInfo &info = iterChapter->second;
		MissionInfo *pMissionInfo = g_GetMissionManager()->GetMissionCfgInfo(info.firstMissionId);
		if (nullptr == pMissionInfo)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  chapter can not find first missionid cfg...chapterid:%u, firstMissionID:%u ", info.chapterId, info.firstMissionId);
			return false;
		}
		//
		MAP_UINT32_UINT32::iterator iterA = mapFirstMissionChapter.find(info.firstMissionId);
		if (iterA != mapFirstMissionChapter.end())
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  chapter first mission belong to more chapter...firstMissionID:%u,belongChapter:%u,chapterid:%u ", info.firstMissionId, iterA->second, info.chapterId);
			return false;
		}
		mapFirstMissionChapter[info.firstMissionId] = info.chapterId;
	}
	mapFirstMissionChapter.clear();

	/*//找出一个章节里面所有的任务
	MissionChapterInfoMap::iterator iterChapterA = _missionChapterMap.begin();
	for (; iterChapterA != _missionChapterMap.end(); ++iterChapterA)
	{
		MissionChapterInfo &info = iterChapter->second;
		if (MISSION_TYPE_ID_TRUNK != info.kind)
		{
			continue;
		}
		uint32_t firstMission = info.firstMissionId;
		MissionInfo *pMissionInfo = GetMissionCfgInfo(firstMission);
		if (nullptr == pMissionInfo)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  chapter first mission can not find mission cfg...firstMissionID:%u,chapterid:%u ", info.firstMissionId, info.chapterId);
			return false;
		}
		uint32_t backMission = pMissionInfo->backTaskId;
		if (backMission <= 0)
		{
			continue;
		}
		MissionInfo *pBackMissionInfo = GetMissionCfgInfo(backMission);
		if (nullptr == pBackMissionInfo)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::LoadConfig  chapter first mission can not find back mission cfg...firstMissionID:%u,chapterid:%u,backMission:%u ", info.firstMissionId, info.chapterId, backMission);
			return false;
		}
	}*/

	//检查主支线任务的后置任务数量,目前主支线任务的后置 在当前条件下只能接取一个，或者只能有一个后置任务
	MissionListMap::iterator backIter = mapPost.begin();
	for (; backIter != mapPost.end(); ++backIter)
	{
		Set &setBack = backIter->second;
		if (setBack.size() > 1)
		{
			char szPre[20] = { '\0' };
			
			snprintf(szPre, 20,"%u == ", backIter->first);
			string strlog = "[logic] check mission:";
			strlog += szPre;
			Set::iterator iterSet = setBack.begin();
			for (; iterSet != setBack.end(); ++iterSet)
			{
				uint32_t missionId = (*iterSet);
				char szTmp[20] = { '\0' };
				snprintf(szTmp, 20,"%u,", missionId);
				strlog += szTmp;
			}
			LogWarningFmtPrint(" %s ", strlog.c_str());
		}
	}
	mapPost.clear();

	//检查有阵营接取条件的主线，并且后置任务为0的任务，这类任务会导致主线任务断了
	MAP_UINT32_UINT32::iterator iterCheck = mapNoBackTrunk.begin();
	for (; iterCheck != mapNoBackTrunk.end(); ++iterCheck)
	{
		LogWarningFmtPrint("MissionManager::LoadConfig...camp trunk mission has no back mission....missionid:%u, chapter:%u ", iterCheck->first, iterCheck->second);
	}

	return true;
}

bool MissionManager::ProcessDyMission()//处理动态任务配置
{
	const TaskdynamicTaskCfgMap *pDymissionCfgMap = g_GetTaskdynamicTaskCfgTable()->GetTaskdynamicTaskCfgMap();
	if (nullptr == pDymissionCfgMap)
	{
		return false;
	}
	TaskdynamicTaskCfgMap::const_iterator iter = pDymissionCfgMap->begin();
	for (; iter != pDymissionCfgMap->end(); ++iter)
	{
		const TaskdynamicTaskCfgInfo &cfg = iter->second;

		DyMissionInfo dyInfo;
		dyInfo.missionId = cfg.taskID;
		dyInfo.kind = cfg.taskType;
		dyInfo.minLev = cfg.minlv;
		dyInfo.maxLev = cfg.maxlv;
		dyInfo.canComplete = cfg.completeCount;
		dyInfo.isShare = cfg.isShare;
		dyInfo.dynamic = cfg.isDynamic;
		dyInfo.useCamp = cfg.isCamptype;
		dyInfo.npcId = cfg.tasknpc;
		dyInfo.name = cfg.remark;
		//随机条件ID列表
		string strCondtion = cfg.idList;
		CommonApi::SplitStrToSetInt(strCondtion, "&", &dyInfo.setComplete);
		//条件ID列表不允许为空
		if (dyInfo.setComplete.size() <= 0)
		{
			MMOLOG_FMT_ERROR("MissionManager::ProcessDyMission....dyInfo.setComplete.size() <= 0...id:%u, str:%s ", dyInfo.missionId, strCondtion.c_str());
			return false;
		}
		//校验所有的条件必须在条件表存在
		SET_INT32::iterator iterCond = dyInfo.setComplete.begin();
		for (; iterCond != dyInfo.setComplete.end(); ++iterCond)
		{
			uint32_t condId = (*iterCond);
			if (nullptr == GetDyConditionCfgInfo(condId))
			{
				MMOLOG_FMT_ERROR("MissionManager::ProcessDyMission....can not find condition config...id:%u, condid:%u ", dyInfo.missionId, condId);
				return false;
			}
		}
		
		//杀怪数量
		string strCount = cfg.monsterCount;
		if (strCount != "")
		{
			CommonApi::SplitStrToVecInt(strCount, "&", &dyInfo.vecMonsNum);
		}		
		//物品数量
		string strItemCount = cfg.itemCount;
		if (strItemCount != "")
		{
			CommonApi::SplitStrToVecInt(strItemCount, "&", &dyInfo.vecItemNum);
		}
		
		//装备数量
		string strEquipCount = cfg.equipCount;
		if (strEquipCount != "")
		{
			CommonApi::SplitStrToVecInt(strEquipCount, "&", &dyInfo.vecEquipNum);
		}
		
		//采集数量
		string strCollectCount = cfg.itemCountCollect;
		if (strCollectCount != "")
		{
			CommonApi::SplitStrToVecInt(strCollectCount, "&", &dyInfo.vecCollectNum);
		}
		
		//场景物件数量
		string strThingCount = cfg.itemCountObject;
		if (strThingCount != "")
		{
			CommonApi::SplitStrToVecInt(strCollectCount, "&", &dyInfo.vecThingNum);
		}
		
		if (nullptr != GetDyMissionCfgInfo(dyInfo.missionId))
		{
			MMOLOG_FMT_ERROR("MissionManager::ProcessDyMission....repeat dynamic mission cfg...id:%u ", dyInfo.missionId);
			return false;
		}

		MAP_INT32_SET_UINT32::iterator iterType = _dymissionTypeMap.find(dyInfo.kind);
		if (iterType != _dymissionTypeMap.end())
		{
			iterType->second.insert(dyInfo.missionId);
		}
		else
		{
			SET_UINT32 setMision;
			setMision.clear();
			setMision.insert(dyInfo.missionId);
			_dymissionTypeMap[dyInfo.kind] = setMision;
		}

		_dymissionInfoMap[dyInfo.missionId] = dyInfo;
	}
	return true;
}

bool MissionManager::ProcessDyCondition() //处理动态条件
{
	const TaskcontentComcondCfgMap *pCondCfgMap = g_GetTaskcontentComcondCfgTable()->GetTaskcontentComcondCfgMap();
	if (nullptr == pCondCfgMap)
	{
		return false;
	}
	TaskcontentComcondCfgMap::const_iterator iter = pCondCfgMap->begin();
	for (; iter != pCondCfgMap->end(); ++iter)
	{
		const TaskcontentComcondCfgInfo &cfg = iter->second;
		DyConditionInfo dyInfo;
		dyInfo.condId = cfg.comcondID;
		//完成场景
		string strMap = cfg.comcondScene;
		CommonApi::SplitStrToSetInt(strMap, "&", &dyInfo.setMap);
		SET_INT32::iterator iterMap = dyInfo.setMap.begin();
		for (; iterMap != dyInfo.setMap.end(); ++iterMap)
		{
			int32_t mapId = (*iterMap);
			
			const MapMapCfgInfo *pMapCfg = g_GetMapMapCfgTable()->GetMapMapCfgInfo(mapId);
			if (nullptr == pMapCfg)
			{
				MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....can not find map cfg...id:%u,mapid:%d ", dyInfo.condId,mapId);
				return false;
			}
			//不允许有动态地图
			if (g_GetMapCfgMgr()->IsDynamic(mapId))
			{
				MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....map is dynamic ...id:%u,mapid:%d ", dyInfo.condId, mapId);
				return false;
			}
			m_setDyMap.insert(mapId);
		}		
		//完成条件
		string strType = cfg.comcondType;
		CommonApi::SplitStrToVecInt(strType, "&", &dyInfo.vecType);
		VEC_INT32::iterator iterType = dyInfo.vecType.begin();
		for (; iterType != dyInfo.vecType.end(); ++iterType)
		{
			int32_t condType = (*iterType);
			//校验条件类型
			if (!ValidCompleteType(condType))
			{
				MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....invalid cond type...id:%u,type:%d ", dyInfo.condId, condType);
				return false;
			}
			if (IsDyCompleteTypeNeedMap(condType))
			{
				if (dyInfo.setMap.size() <= 0)
				{
					MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....cond type need mapid,but can not find in config...id:%u,type:%d ", dyInfo.condId, condType);
					return false;
				}
			}
		}
		if (dyInfo.vecType.size() <= 0)
		{
			MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....cond type size error...id:%u ", dyInfo.condId);
			return false;
		}
		//完成条件概率
		string strRate = cfg.comcondRandomValue;
		if (strRate != "")
		{
			CommonApi::SplitStrToVecInt(strRate, "&", &dyInfo.vecRate);
		}	

		//当概率vector大于0的时候，说明要使用概率
		if (dyInfo.vecRate.size() > 0 && dyInfo.vecType.size() != dyInfo.vecRate.size())
		{
			MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....cond type size not equal cond rate...id:%u ", dyInfo.condId);
			return false;
		}
		if (dyInfo.vecRate.size() > 0)
		{
			VEC_INT32::iterator iter = dyInfo.vecRate.begin();
			for (; iter != dyInfo.vecRate.end(); ++iter)
			{
				dyInfo.totalRate += (*iter);
			}
		}

		if (nullptr != GetDyConditionCfgInfo(dyInfo.condId))
		{
			MMOLOG_FMT_ERROR("MissionManager::ProcessDyCondition....repeat cond cfg...id:%u ", dyInfo.condId);
			return false;
		}
		_dycondtionInfoMap[dyInfo.condId] = dyInfo;
	}
	return true;
}

//组装text表的key
uint64_t MissionManager::ComposeTextKey(uint32_t mapId, int32_t missionType, int32_t condType, int32_t camp)
{
	uint64_t resmapId = (uint64_t)mapId;
	int32_t resmissionType = (int32_t)missionType;
	int32_t rescondType = (int32_t)condType;
	int32_t rescamp = (int32_t)camp;

	uint64_t key = DY_MISSION_TEXT_KEY(resmapId, resmissionType, rescondType, rescamp);
	return key;
}

bool MissionManager::ProcessDyText()	//处理动态任务前端显示
{
	const TaskcontentTextCfgMap *pTextCfg = g_GetTaskcontentTextCfgTable()->GetTaskcontentTextCfgMap();
	if (nullptr != pTextCfg)
	{
		TaskcontentTextCfgMap::const_iterator iter = pTextCfg->begin();
		for (; iter != pTextCfg->end(); ++iter)
		{
			const TaskcontentTextCfgInfo &info = iter->second;
			VEC_INT32 vecTaskType;
			vecTaskType.clear();
			if (info.taskType != "")
			{
				string strType = info.taskType;
				CommonApi::SplitStrToVecInt(strType, "&", &vecTaskType);
			}
			if (vecTaskType.size() <= 0)
			{
				continue;
			}
			SET_UINT64 setKey;
			setKey.clear();
			//
			VEC_INT32 vecCamp;
			vecCamp.clear();
			vecCamp.push_back(info.campType);
			if (0 == info.campType)//为0 表示所有阵营通用的
			{
				vecCamp.push_back(ECamp_Type_Light);
				vecCamp.push_back(ECamp_Type_Dark);
			}
			VEC_INT32::iterator iterType = vecTaskType.begin();
			for (; iterType != vecTaskType.end();++iterType)
			{
				int32_t taskType = (*iterType);
				VEC_INT32::iterator iterCamp = vecCamp.begin();
				for (; iterCamp != vecCamp.end(); ++iterCamp)
				{
					int32_t camp = (*iterCamp);
					uint64_t key = ComposeTextKey(info.comcondScene, taskType, info.comcondType, camp);
					setKey.insert(key);
				}
			}
			//
			SET_UINT64::iterator iterKey = setKey.begin();
			for (; iterKey != setKey.end(); ++iterKey)
			{
				uint64_t keyA = (*iterKey);
				MAP_UINT64_SET_UINT32::iterator iterKeyEx = _dymissionTextMap.find(keyA);
				if (iterKeyEx != _dymissionTextMap.end())
				{
					iterKeyEx->second.insert(info.textID);
				}
				else
				{
					SET_UINT32 setText;
					setText.clear();
					setText.insert(info.textID);
					_dymissionTextMap[keyA] = setText;
				}
			}			
		}
	}

	return true;
}

//解析任务外部类型
void MissionManager::ParseTaskOutType(MissionChapterInfo &info, std::string sOutType)
{
	std::vector<std::string> vecStr;
	CommonApi::SplitStr(sOutType, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		if (vecStr[i] == "")
		{
			continue;
		}

		int32_t otype = atoi(vecStr[i].c_str());
		if (otype <= 0)
		{
			continue;
		}

		info.vecOuttype.push_back(otype);
	}
}
//初始化任务外部类型触发外部系统对应类型
void MissionManager::InitTriggerOut()
{
}

bool MissionManager::ProcessMapData() //处理动态任务相关的地图数据
{
	SET_UINT32::iterator iterSet = m_setDyMap.begin();
	for (; iterSet != m_setDyMap.end(); ++iterSet)
	{
		uint32_t mapId = (*iterSet);
		//怪物
		const MapLoactionCfg::MonsterRefLocationMap*pMonsLocMap = g_GetMapLocationCfg()->getMonsRefMap(mapId);
		if (nullptr != pMonsLocMap)
		{
			MAP_INT32_SET_UINT32 mapParmType;
			mapParmType.clear();
			MAP_INT32_SET_UINT32 mapCollectThingParmType;
			mapCollectThingParmType.clear();
			MAP_INT32_SET_UINT32 mapUseThingParmType;
			mapUseThingParmType.clear();
			MapLoactionCfg::MonsterRefLocationMap::const_iterator iterMon = pMonsLocMap->begin();
			for (; iterMon != pMonsLocMap->end(); ++iterMon)
			{
				const std::vector<MonsterRefLocation> &vecMonsRef = iterMon->second;
				if (vecMonsRef.size() <= 0)
				{
					continue;
				}
				const MonsterRefLocation &loc = (*vecMonsRef.begin());
				const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(loc.m_id);
				if (nullptr == pMonsCfg || pMonsCfg->dynamictaskValue <= 0)
				{
					continue;
				}
				if (PARENT_MONSTER_TYPE_MONSTER == pMonsCfg->parentType)
				{
					//pMonsCfg->dynamictaskValue字段表示 1=光耀阵营倾向，2=暗夜阵营倾向，3=中立，4=藏宝图刷新monster
					MAP_INT32_SET_UINT32::iterator iterType = mapParmType.find(pMonsCfg->dynamictaskValue);
					if (iterType != mapParmType.end())
					{
						iterType->second.insert(pMonsCfg->monsterID);
					}
					else
					{
						SET_UINT32 setMons;
						setMons.clear();
						setMons.insert(pMonsCfg->monsterID);
						mapParmType[pMonsCfg->dynamictaskValue] = setMons;
					}
				}
				else if (PARENT_MONSTER_TYPE_CAN_USE_DROP == pMonsCfg->parentType) //可采集物件
				{
					MAP_INT32_SET_UINT32::iterator iterType = mapCollectThingParmType.find(pMonsCfg->dynamictaskValue);
					if (iterType != mapCollectThingParmType.end())
					{
						iterType->second.insert(pMonsCfg->monsterID);
					}
					else
					{
						SET_UINT32 setMons;
						setMons.clear();
						setMons.insert(pMonsCfg->monsterID);
						mapCollectThingParmType[pMonsCfg->dynamictaskValue] = setMons;
					}
				}
				else if (PARENT_MONSTER_TYPE_CAN_USE_THING == pMonsCfg->parentType) //可使用物件
				{
					MAP_INT32_SET_UINT32::iterator iterType = mapUseThingParmType.find(pMonsCfg->dynamictaskValue);
					if (iterType != mapUseThingParmType.end())
					{
						iterType->second.insert(pMonsCfg->monsterID);
					}
					else
					{
						SET_UINT32 setMons;
						setMons.clear();
						setMons.insert(pMonsCfg->monsterID);
						mapUseThingParmType[pMonsCfg->dynamictaskValue] = setMons;
					}
				}
			}

			if (mapParmType.size() > 0)
			{
				m_mapMapMonsParam[mapId] = mapParmType;
			}
			if (mapUseThingParmType.size() > 0)
			{
				m_mapMapUseThingParam[mapId] = mapUseThingParmType;
			}
			if (mapCollectThingParmType.size() > 0)
			{
				m_mapMapCollectThingParam[mapId] = mapCollectThingParmType;
			}
		}

		//NPC
		std::vector<NPCRefLocation>*pNpcLocVec = g_GetMapLocationCfg()->getNPCRefLoc(mapId);
		if (nullptr != pNpcLocVec)
		{
			MAP_INT32_SET_UINT32 mapParmType;
			mapParmType.clear();
			std::vector<NPCRefLocation> *pVecNpcLoc = g_GetMapLocationCfg()->getNPCRefLoc(mapId);
			if (nullptr != pVecNpcLoc)
			{
				std::vector<NPCRefLocation>::iterator iterNpc = pVecNpcLoc->begin();
				for (; iterNpc != pVecNpcLoc->end(); ++iterNpc)
				{
					const NPCRefLocation &loc = (*iterNpc);
					const NpcNpcCfgInfo *pNpcCfg = g_GetNpcNpcCfgTable()->GetNpcNpcCfgInfo(loc.m_id);
					if (nullptr != pNpcCfg && pNpcCfg->dynamictaskValue > 0)
					{
						//pNpcCfg->dynamictaskValue 表示 1 = 光耀阵营倾向，2 = 暗夜阵营倾向，3 = 中立，4 = 藏宝图刷新
						MAP_INT32_SET_UINT32::iterator iterType = mapParmType.find(pNpcCfg->dynamictaskValue);
						if (iterType != mapParmType.end())
						{
							iterType->second.insert(pNpcCfg->npcID);
						}
						else
						{
							SET_UINT32 setNpc;
							setNpc.clear();
							setNpc.insert(pNpcCfg->npcID);
							mapParmType[pNpcCfg->dynamictaskValue] = setNpc;
						}
					}
				}
			}
			if (mapParmType.size() > 0)
			{
				m_mapMapNpcParam[mapId] = mapParmType;
			}			
		}

		//区域
		MAP_INT32_SET_UINT32 mapAreaParmType;
		mapAreaParmType.clear();
		VEC_UINT32 vecArea;
		vecArea.clear();
		g_GetMapLocationCfg()->GetAreaIdByMap(mapId, vecArea);
		VEC_UINT32::iterator iterArea = vecArea.begin();
		for (; iterArea != vecArea.end(); ++iterArea)
		{
			uint32_t areaId = (*iterArea);
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr != pAreaCfg && pAreaCfg->dynamictaskValue > 0)
			{
				//pAreaCfg->dynamictaskValue 表示 1 = 光耀阵营倾向，2 = 暗夜阵营倾向，3 = 中立，4 = 藏宝图刷新
				MAP_INT32_SET_UINT32::iterator iterType = mapAreaParmType.find(pAreaCfg->dynamictaskValue);
				if (iterType != mapAreaParmType.end())
				{
					iterType->second.insert(areaId);
				}
				else
				{
					SET_UINT32 setAreaEx;
					setAreaEx.clear();
					setAreaEx.insert(areaId);
					mapAreaParmType[pAreaCfg->dynamictaskValue] = setAreaEx;
				}
				m_setAllArea.insert(areaId);
			}
		}
		if (mapAreaParmType.size() > 0)
		{
			m_mapMapAreaParam[mapId] = mapAreaParmType;
		}
	}

	//藏宝图怪物地编里面没有，只配置再excel中
	const MonsterMonsterCfgMap *pMonsMap = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgMap();
	if (nullptr != pMonsMap)
	{
		MonsterMonsterCfgMap::const_iterator iterMons = pMonsMap->begin();
		for (; iterMons != pMonsMap->end(); ++iterMons)
		{
			const MonsterMonsterCfgInfo &stMonsCfg = iterMons->second;
			if (MISSION_PARAM_TYPE_TREASURE != stMonsCfg.dynamictaskValue)
			{
				continue;
			}

			MAP_INT32_SET_UINT32::iterator iter = m_mapNoMapMonsParam.find(stMonsCfg.dynamictaskValue);
			if (iter != m_mapNoMapMonsParam.end())
			{
				iter->second.insert(stMonsCfg.dynamictaskValue);
			}
			else
			{
				SET_UINT32 setParam;
				setParam.insert(stMonsCfg.monsterID);
				m_mapNoMapMonsParam[stMonsCfg.dynamictaskValue] = setParam;
			}
		}
	}


	//采集物, 采集物分前端采集和后端采集，前端采集不依赖地图
	const ThingCollectCfgMap *pThingCollectMap = g_GetThingCollectCfgTable()->GetThingCollectCfgMap();
	if (nullptr != pThingCollectMap)
	{
		ThingCollectCfgMap::const_iterator iterCollect = pThingCollectMap->begin();
		for (; iterCollect != pThingCollectMap->end(); ++iterCollect)
		{
			const ThingCollectCfgInfo &info = iterCollect->second;
			if (info.dynamictaskValue <= 0)
			{
				continue;
			}
			uint32_t areaId = info.dynamictaskValue; //采集表这个字段对应区域ID
			//查询下这个区域是否是阵营区域
			SET_UINT32::iterator iterFind = m_setAllArea.find(areaId);
			if (iterFind == m_setAllArea.end())
			{
				MMOLOG_FMT_ERROR("MissionManager::ProcessMapData....can not find area...areaid:%u, collectid:%u ", areaId, info.id);
				return false;
			}
			MAP_UINT32_SET_UINT32::iterator iterArea = m_mapAreaToClientCollect.find(areaId);
			if (iterArea != m_mapAreaToClientCollect.end())
			{
				iterArea->second.insert(info.id);
			}
			else
			{
				SET_UINT32 setColl;
				setColl.clear();
				setColl.insert(info.id);
				m_mapAreaToClientCollect[areaId] = setColl;
			}
			if (info.drop > 0) //对应任务宝箱ID
			{
				//这里实际上 一个采集物对一个宝箱ID，但是为了处理方便统一用set保存
				SET_UINT32 setBox;
				setBox.clear();
				setBox.insert(info.drop);
				m_mapCollectToBox[info.id] = setBox;
			}
		}
	}


	//因为区域对应 采集物ID，也对应 buttonid，一个区域如果只是对应采集物而没有对应buttonid的话会出现button随机区域的时候随机的区域
	MAP_UINT32_MAP_INT32_SET_UINT32::iterator iterE = m_mapMapAreaParam.begin();
	for (; iterE != m_mapMapAreaParam.end(); ++iterE)
	{
		uint32_t mapId = iterE->first;
		MAP_INT32_SET_UINT32 &mapAreaParmType = iterE->second;
		MAP_INT32_SET_UINT32 mapCollAreaParmType;
		mapCollAreaParmType.clear();
		MAP_INT32_SET_UINT32::iterator iterTypeA = mapAreaParmType.begin();
		for (; iterTypeA != mapAreaParmType.end(); ++iterTypeA)
		{
			int32_t type = iterTypeA->first;
			if (MISSION_PARAM_TYPE_LIGHT == type
				|| MISSION_PARAM_TYPE_DARK == type
				|| MISSION_PARAM_TYPE_MID == type
				)
			{
				SET_UINT32 &setType = iterTypeA->second;
				SET_UINT32::iterator iterArea = setType.begin();
				for (; iterArea != setType.end(); ++iterArea)
				{
					uint32_t areaId = (*iterArea);
					MAP_UINT32_SET_UINT32::iterator iterColl = m_mapAreaToClientCollect.find(areaId);
					if (iterColl == m_mapAreaToClientCollect.end())
					{
						continue;
					}
					MAP_INT32_SET_UINT32::iterator iterTypeB = mapCollAreaParmType.find(type);
					if (iterTypeB != mapCollAreaParmType.end())
					{
						iterTypeB->second.insert(areaId);
					}
					else
					{
						SET_UINT32 setAreaEx;
						setAreaEx.clear();
						setAreaEx.insert(areaId);
						mapCollAreaParmType[type] = setAreaEx;
					}
				}
			}
		}
		if (mapCollAreaParmType.size() > 0)
		{
			m_mapMapCollectAreaParam[mapId] = mapCollAreaParmType;
		}
	}
	

	

	return true;
}

bool MissionManager::ProcessItemData() //处理动态任务相关的物品数据
{
	const ItemItemCfgMap *pItemCfgMap = g_GetItemItemCfgTable()->GetItemItemCfgMap();
	if (nullptr != pItemCfgMap)
	{
		const ConstantConstantCfgInfo *pConstCfg = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Player_Level_Max);
		if (nullptr == pConstCfg)
		{
			MMOLOG_FMT_ERROR("ProcessItemData can not find player max level....id:%d", EArg_Player_Level_Max);
			return false;
		}

		string strEmpty = "";
		ItemItemCfgMap::const_iterator iterItem = pItemCfgMap->begin();
		for (; iterItem != pItemCfgMap->end(); ++iterItem)
		{
			const ItemItemCfgInfo &info = iterItem->second;
			if ((info.dynamictaskLevel == "") || (info.dynamictaskType == ""))
			{
				continue;
			}
			//info.dynamictaskType:填写tasktype的任务类型，指定任务类型可以使用改物品作为随机任务使用，填写-1表示所有任务类型都可以使用
			//info.dynamictaskLevel: 填写的等级代表随机任务范围包含 该等级则会随机使用该物品，填写-1表示所有等级都可以使用
			VEC_INT32 vecType;
			vecType.clear();
			CommonApi::SplitStrToVecInt(info.dynamictaskType, ",", &vecType);
			if (vecType.size() <= 0)
			{
				MMOLOG_FMT_ERROR("ProcessItemData.....vecType.size() <= 0...itemid:%u, str:%s ", info.id, info.dynamictaskType.c_str());
				return false;
			}

			//检查是否有 -1
			bool alltype = false;
			VEC_INT32::iterator iterType = vecType.begin();
			for (; iterType != vecType.end(); ++iterType)
			{
				int32_t type = (*iterType);
				if (MISSION_ALL_DY_MISSION_TYPE == type)
				{
					alltype = true;
					break;
				}
				else if (!ValidMissionType(type))
				{
					MMOLOG_FMT_ERROR("ProcessItemData.....!ValidMissionType(type)...itemid:%u, str:%s, type:%d ", info.id, info.dynamictaskType.c_str(),type);
					return false;
				}
			}

			string dynamictaskNum = info.dynamictaskNum;
			VEC_INT32 vecNum;
			vecNum.clear();
			CommonApi::SplitStrToVecInt(dynamictaskNum, ",", &vecNum);
			if (vecNum.size() <= 0)
			{
				MMOLOG_FMT_ERROR("ProcessItemData.....vecNum.size() <= 0...itemid:%u, str:%s ", info.id, dynamictaskNum.c_str());
				return false;
			}
			if (vecNum.size() != vecType.size())
			{
				MMOLOG_FMT_ERROR("ProcessItemData.....vecNum.size() != vecType.size()...itemid:%u, str:%s ", info.id, dynamictaskNum.c_str());
				return false;
			}
			//检查物品数量
			for (VEC_INT32::iterator iterNum = vecNum.begin(); iterNum != vecNum.end(); ++iterNum)
			{
				int32_t nNum = (*iterNum);
				if (nNum <= 0)
				{
					MMOLOG_FMT_ERROR("ProcessItemData.....nNum <= 0...itemid:%u, str:%s ", info.id, dynamictaskNum.c_str());
					return false;
				}
			}
			if (alltype && 1 != vecNum.size())//使用全部类型的时候，数量size必须为 1
			{
				MMOLOG_FMT_ERROR("ProcessItemData.....alltype && 1 != vecNum.size()...itemid:%u, str:%s ", info.id, dynamictaskNum.c_str());
				return false;
			}

			//
			VEC_INT32 vecLevel;
			vecLevel.clear();
			CommonApi::SplitStrToVecInt(info.dynamictaskLevel, ",", &vecLevel);
			if (vecLevel.size() <= 0)
			{
				MMOLOG_FMT_ERROR("ProcessItemData.....vecLevel.size() <= 0...itemid:%u, str:%s ", info.id, info.dynamictaskLevel.c_str());
				return false;
			}
			//检查是否有 -1
			bool alllevel = false;
			VEC_INT32::iterator iterLev = vecLevel.begin();
			for (; iterLev != vecLevel.end(); ++iterLev)
			{
				int32_t lev = (*iterLev);
				if (MISSION_ALL_DY_ITEM_LEVEL == lev)
				{
					alllevel = true;
					break;
				}
			}

			//统计类型
			MAP_INT8_MAP_UINT32_UINT32 mapTypeItemNum;
			mapTypeItemNum.clear();
			SET_UINT32 setType;
			setType.clear();
			if (alltype) //所有类型
			{
				MAP_UINT32_UINT32 mapItemNum;
				mapItemNum.clear();
				mapItemNum[info.id] = vecNum.at(0);//所有类型数量只有一列
				const SET_INT32 &setAll = AllMissionType();
				SET_INT32::const_iterator iterAll = setAll.begin();
				for (; iterAll != setAll.end(); ++iterAll)
				{
					mapTypeItemNum[(*iterAll)] = mapItemNum;
				}
			}
			else
			{
				MAP_UINT32_UINT32 mapItemNum;
				mapItemNum.clear();
				int32_t iszie = vecType.size();
				for (int32_t i = 0; i < iszie; ++i)
				{
					mapItemNum.clear();
					mapItemNum[info.id] = vecNum[i];
					mapTypeItemNum[vecType[i]] = mapItemNum;
				}
			}
			//统计等级
			SET_UINT32 setLevel;
			setLevel.clear();
			if (alllevel) //所有等级
			{
				for (int32_t i = 1; i <= pConstCfg->constantdata; ++i)
				{
					setLevel.insert(i);
				}
			}
			else
			{
				VEC_INT32::iterator iterLevEx = vecLevel.begin();
				for (; iterLevEx != vecLevel.end(); ++iterLevEx)
				{
					int32_t lev = (*iterLevEx);
					setLevel.insert(lev);
				}
			}
			MAP_INT8_MAP_UINT32_UINT32::iterator iterTypeA = mapTypeItemNum.begin();
			for (; iterTypeA != mapTypeItemNum.end(); ++iterTypeA)
			{
				int8_t missionType = iterTypeA->first;
				MAP_UINT32_UINT32 &mapItemNum = iterTypeA->second;
				SET_UINT32::iterator iterLevRes = setLevel.begin();
				for (; iterLevRes != setLevel.end(); ++iterLevRes)
				{
					uint32_t lev = (*iterLevRes);
					
					MAP_INT8_MAP_UINT32_MAP_UINT32_UINT32::iterator iterTypeRes = m_mapMissionTypeLevItemNum.find(missionType);
					if (iterTypeRes != m_mapMissionTypeLevItemNum.end())
					{
						MAP_UINT32_MAP_UINT32_UINT32 &mapLevItemNum = iterTypeRes->second;
						MAP_UINT32_MAP_UINT32_UINT32::iterator iterLev = mapLevItemNum.find(lev);
						if (iterLev != mapLevItemNum.end())
						{
							MAP_UINT32_UINT32 &mapItemNumRes = iterLev->second;
							//
							MAP_UINT32_UINT32::iterator iterItem = mapItemNum.begin();
							for (; iterItem != mapItemNum.end(); ++iterItem)
							{
								MAP_UINT32_UINT32::iterator iteritemRes = mapItemNumRes.find(iterItem->first);
								if (iteritemRes != mapItemNumRes.end())
								{
									MMOLOG_FMT_ERROR("ProcessItemData.....iteritemRes != mapItemNumRes.end()....id:%u, itemid:%u ", info.id, iterItem->first);
									return false;
								}
								mapItemNumRes[iterItem->first] = iterItem->second;
							}
						}
						else
						{
							mapLevItemNum[lev] = mapItemNum;
						}
						
					}
					else
					{
						MAP_UINT32_MAP_UINT32_UINT32 mapLevItemNum;
						mapLevItemNum[lev] = mapItemNum;
						m_mapMissionTypeLevItemNum[missionType] = mapLevItemNum;
					}
				} // end of for (; iterLevRes != setLevel.end(); ++iterLevRes)
			} // end of for (; iterTypeA != mapTypeItemNum.end(); ++iterTypeA)
		}
	}
	return true;
}

bool MissionManager::ProcessEquipData()//处理动态任务相关的装备数据
{
	const EquipEquipCfgMap *pEqupMap = g_GetEquipEquipCfgTable()->GetEquipEquipCfgMap();
	if (nullptr != pEqupMap)
	{
		EquipEquipCfgMap::const_iterator iter = pEqupMap->begin();
		for (; iter != pEqupMap->end(); ++iter)
		{
			const EquipEquipCfgInfo &info = iter->second;
			//填写等级，不填则不用。用以区分该equip是否用于动态任务及用于哪个等级段
			int32_t lev = info.dynamictaskValue;
			ORDER_MAP_UINT32_SET_UINT32::iterator iterLev = m_mapLevEquip.find(lev);
			if (iterLev != m_mapLevEquip.end())
			{
				iterLev->second.insert(info.id);
			}
			else
			{
				SET_UINT32 setEquip;
				setEquip.clear();
				setEquip.insert(info.id);
				m_mapLevEquip[lev] = setEquip;
			}
		}
	}
	return true;
}

bool MissionManager::ProcessBoxData()//处理动态任务相关的box数据
{
	const BoxDropCfgMap *pBoxCfgMap = g_GetBoxDropCfgTable()->GetBoxDropCfgMap();
	if (nullptr != pBoxCfgMap)
	{
		BoxDropCfgMap::const_iterator iterBox = pBoxCfgMap->begin();
		for (; iterBox != pBoxCfgMap->end(); ++iterBox)
		{
			const BoxDropCfgInfo &info = iterBox->second;
			if (info.dynamictaskValue <= 0)
			{
				continue;
			}
			uint32_t monsId = info.dynamictaskValue;//box表这个字段表示怪物ID
			MAP_UINT32_SET_UINT32::iterator iterMons = m_mapMonsToBox.find(monsId);
			if (iterMons != m_mapMonsToBox.end())
			{
				iterMons->second.insert(info.id);
			}
			else
			{
				SET_UINT32 setBox;
				setBox.clear();
				setBox.insert(info.id);
				m_mapMonsToBox[monsId] = setBox;
			}
		}
	}
	return true;
}

bool MissionManager::ProcessButtonData()		//处理动态任务相关的行为按钮
{
	const ButtonButtonCfgMap *pButtonCfgMap = g_GetButtonButtonCfgTable()->GetButtonButtonCfgMap();
	if (nullptr != pButtonCfgMap)
	{
		ButtonButtonCfgMap::const_iterator iter = pButtonCfgMap->begin();
		for (; iter != pButtonCfgMap->end(); ++iter)
		{
			const ButtonButtonCfgInfo &info = iter->second;
			if (info.dynamictaskValue <= 0)
			{
				continue;
			}
			uint32_t areaId = info.dynamictaskValue;//行为按钮表这个字段表示区域ID
			MAP_UINT32_SET_UINT32::iterator iterArea = m_mapAreaToButton.find(areaId);
			if (iterArea != m_mapAreaToButton.end())
			{
				iterArea->second.insert(info.id);
			}
			else
			{
				SET_UINT32 setButton;
				setButton.clear();
				setButton.insert(info.id);
				m_mapAreaToButton[areaId] = setButton;
			}
		}
	}

	//因为区域对应 采集物ID，也对应 buttonid，一个区域如果只是对应采集物而没有对应buttonid的话会出现button随机到的区域是无效区域
	MAP_UINT32_MAP_INT32_SET_UINT32::iterator iterMap = m_mapMapAreaParam.begin();
	for (; iterMap != m_mapMapAreaParam.end(); ++iterMap)
	{
		uint32_t mapId = iterMap->first;
		MAP_INT32_SET_UINT32 mapButtonAreaParmType;
		mapButtonAreaParmType.clear();
		//
		MAP_INT32_SET_UINT32 &mapAreaParmType = iterMap->second;
		MAP_INT32_SET_UINT32::iterator iterTypeA = mapAreaParmType.begin();
		for (; iterTypeA != mapAreaParmType.end(); ++iterTypeA)
		{
			int32_t type = iterTypeA->first;
			if (MISSION_PARAM_TYPE_LIGHT == type
				|| MISSION_PARAM_TYPE_DARK == type
				|| MISSION_PARAM_TYPE_MID == type
				)
			{
				SET_UINT32 &setType = iterTypeA->second;
				SET_UINT32::iterator iterArea = setType.begin();
				for (; iterArea != setType.end(); ++iterArea)
				{
					uint32_t areaId = (*iterArea);
					MAP_UINT32_SET_UINT32::iterator iterBtn = m_mapAreaToButton.find(areaId);
					if (iterBtn == m_mapAreaToButton.end())
					{
						continue;
					}
					MAP_INT32_SET_UINT32::iterator iterTypeB = mapButtonAreaParmType.find(type);
					if (iterTypeB != mapButtonAreaParmType.end())
					{
						iterTypeB->second.insert(areaId);
					}
					else
					{
						SET_UINT32 setAreaEx;
						setAreaEx.clear();
						setAreaEx.insert(areaId);
						mapButtonAreaParmType[type] = setAreaEx;
					}
				}
			}
		}

		if (mapButtonAreaParmType.size() > 0)
		{
			m_mapMapButtonAreaParam[mapId] = mapButtonAreaParmType;
		}

	} // end of for (; iterMap != m_mapMapAreaParam.end(); ++iterMap)

	return true;
}

bool MissionManager::CheckFirstChapter() //检查第一个主线章节ID
{
	const TasktrackerFirstChapterCfgMap *pMap = g_GetTasktrackerFirstChapterCfgTable()->GetTasktrackerFirstChapterCfgMap();
	if (nullptr == pMap)
	{
		LogErrFmtPrint("MissionManager::CheckFirstChapter()....nullptr == pMap");
		return false;
	}
	if (pMap->size() <= 0)
	{
		LogErrFmtPrint("MissionManager::CheckFirstChapter()....pMap->size() <= 0");
		return false;
	}
	TasktrackerFirstChapterCfgMap::const_iterator iter = pMap->begin();
	for (; iter != pMap->end(); ++iter)
	{
		const MissionChapterInfo *pChapterCfg = GetMissionChapterCfgInfo(iter->second.firstChapterId);
		if (nullptr == pChapterCfg)
		{
			LogErrFmtPrint("MissionManager::CheckFirstChapter()...nullptr == pChapterCfg, chapterid:%u ", iter->second.firstChapterId);
			return false;
		}
	}

	return true;
}

void MissionManager::ParseChapterReward(uint32_t chapterId, vector<TaskComplex> &reward, string strParam)//解析章节奖励
{
	std::vector<std::string> vecStr;
	vecStr.clear();
	//接取分隔符
	CommonApi::SplitStr(strParam, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseChapterReward but size not equal 6 ...chapterid=%u", chapterId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());
		reward.push_back(complex);
	}
}

//解析接取条件(公用接口)
bool MissionManager::ParseAcceptCond(AcceptInfo &accept, std::string strAcceptParam, SParaseAcceptParam &param)
{
	std::vector<std::string> vecStr;
	vecStr.clear();
	//接取分隔符
	CommonApi::SplitStr(strAcceptParam, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);
		int32_t isize = sonVecStr.size();
		if (isize != 6)
		{
			MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....isize != 6...kind:%u,chapterid:%u,adventureid:%u, isize:%d ", param.kind,param.chapterId,param.adventureId, isize);
			return false;
		}

		//第一位表示的是类型
		if (sonVecStr[0] == "")
		{
			continue;
		}
		uint32_t type = atoi(sonVecStr[0].c_str());

		// M_ACCEPT_TYPE_PRE_OR_CHAPTER  和  M_ACCEPT_TYPE_PRE_AND_MISSION 只允许出现再支线中
		if ((M_ACCEPT_TYPE_PRE_OR_CHAPTER == type || M_ACCEPT_TYPE_PRE_AND_CHAPTER == type)
			&& param.kind != MISSION_TYPE_ID_BRANCH && param.kind != MISSION_TYPE_ID_ADVENTURE
			)
		{
			MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....M_ACCEPT_TYPE_PRE_OR_CHAPTER and M_ACCEPT_TYPE_PRE_AND_CHAPTER is only allowed in branch and adventure mission...chapterid:%u,kind:%u,adventureid:%u,accept_type:%u", param.chapterId, param.kind,param.adventureId, type);
			return false;
		}
		//解析该类型下面的数据
		//前置任务（或关系）
		if (type == M_ACCEPT_TYPE_PRE_OR_CHAPTER)
		{
			for (int32_t i = 1; i < 6; ++i)
			{
				uint32_t preId = atoi(sonVecStr[i].c_str());
				if (preId > 0)
				{
					accept.setPreOrChapter.insert(preId);
				}
			}
		}
		//职业
		else if (type == M_ACCEPT_TYPE_PROFESSION)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.profession = atoi(sonVecStr[1].c_str());
			if (!ECharacterProf_IsValid(accept.profession))
			{

				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....ECharacterProf_IsValid...chapterid:%u,kind:%u,adventureid:%u,accept_type:%u,prof:%u ", param.chapterId, param.kind, param.adventureId, type, accept.profession);
				return false;
			}
		}
		//性别
		else if (type == M_ACCEPT_TYPE_SEX)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}

			accept.sex = atoi(sonVecStr[1].c_str());
			if (!ECharacterSex_IsValid(accept.sex))
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....ECharacterSex_IsValid...chapterid:%u,kind:%u,adventureid:%u,accept_type:%u,sex:%u ", param.chapterId, param.kind, param.adventureId, type,accept.sex);
				return false;
			}
		}
		//阵营
		else if (type == M_ACCEPT_TYPE_CAMP)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.camp = atoi(sonVecStr[1].c_str());
			if (ECamp_Type_Light != accept.camp && ECamp_Type_Dark != accept.camp)
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....invalid camp...chapterid:%u,kind:%u,adventureid:%u,accept_type:%u,camp:%u ", param.chapterId, param.kind, param.adventureId, type, accept.camp);
				return false;
			}
		}
		//种族
		else if (type == M_ACCEPT_TYPE_RACE)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			//种族
			accept.race = atoi(sonVecStr[1].c_str());

			if (!ERace_IsValid(accept.race))
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....ERace_IsValid...chapterid:%u,kind:%u,adventureid:%u,accept_type:%u,race:%u ", param.chapterId, param.kind, param.adventureId, type,accept.race);
				return false;
			}
		}
		//互斥章节
		else if (type == M_ACCEPT_TYPE_MUT_CHAPTER)
		{
			for (int32_t i = 1; i < 6; ++i)
			{
				uint32_t mutId = atoi(sonVecStr[i].c_str());
				if (mutId > 0)
				{
					accept.setMutChapter.insert(mutId);
				}
			}
		}		
		//前置任务（与关系）
		else if (type == M_ACCEPT_TYPE_PRE_AND_CHAPTER)
		{
			for (int32_t i = 1; i < 6; ++i)
			{
				uint32_t preId = atoi(sonVecStr[i].c_str());
				if (preId > 0)
				{
					accept.setPreAndChapter.insert(preId);
				}
			}
		}
		//工会
		else if (type == M_ACCEPT_TYPE_FAMILY)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.guild = atoi(sonVecStr[1].c_str());
		}
		//组队
		else if (type == M_ACCEPT_TYPE_TEAM)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.team = atoi(sonVecStr[1].c_str());
		}
		//处于区域内
		else if (type == M_ACCEPT_TYPE_IN_AREA)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.inarea = atoi(sonVecStr[1].c_str());
		}
		//处于地图
		else if (type == M_ACCEPT_TYPE_IN_MAP)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.inmap = atoi(sonVecStr[1].c_str());
		}
		//位面限制
		else if (type == M_ACCEPT_TYPE_PLANE)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.plane = atoi(sonVecStr[1].c_str());
		}
		//指定时间段
		else if (type == M_ACCEPT_TYPE_TIME)
		{
			if (sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
			{
				continue;
			}
			accept.openHour = atoi(sonVecStr[2].c_str());
			accept.openMin = atoi(sonVecStr[3].c_str());
			accept.lastMin = atoi(sonVecStr[4].c_str());
			if (accept.openHour < 0 || accept.openHour > 24)
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....accept.openHour < 0 || accept.openHour > 24...kind:%u,chapterid:%u,adventureid:%u,type:%u, openhour:%d ", param.kind, param.chapterId, param.adventureId, type, accept.openHour);
				return false;
			}
			if (accept.openMin < 0 || accept.openMin > 60)
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....accept.openMin < 0 || accept.openMin > 60...kind:%u,chapterid:%u,adventureid:%u,type:%u, openmin:%d ", param.kind, param.chapterId, param.adventureId, type, accept.openMin);
				return false;
			}
			if (accept.lastMin <= 0)
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....accept.lastMin <= 0...kind:%u,chapterid:%u,adventureid:%u,type:%u, lastmin:%d ", param.kind, param.chapterId, param.adventureId, type, accept.lastMin);
				return false;
			}
		}
		//指定星期
		else if (type == M_ACCEPT_TYPE_WEEK)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			int32_t iVal = atoi(sonVecStr[1].c_str());
			while (iVal > 0)
			{
				int32_t week = iVal % 10;
				if (week < 1 || week > 7)
				{
					MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....week < 1 || week > 7...kind:%u,chapterid:%u,adventureid:%u,type:%u, week:%d,ival:%d ", param.kind, param.chapterId, param.adventureId, type, week, iVal);
					return false;
				}
				accept.setOpenWeek.insert(week);
				//
				iVal = iVal / 10;
			}
		}
		//已携带物品
		else if (type == M_ACCEPT_TYPE_HAS_ITEM)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			SItem item;
			item.nItemID = atoi(sonVecStr[1].c_str());
			item.nNum = atoi(sonVecStr[2].c_str());
			item.byBind = (int8_t)EBindState::EBindState_all;
			if (item.nItemID <= 0 || item.nNum <= 0)
			{
				MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....item.nItemID <= 0 || item.nNum <= 0...kind:%u,chapterid:%u,adventureid:%u,type:%u,itemid:%u,itemnum:%d ", param.kind, param.chapterId, param.adventureId, type,item.nItemID,item.nNum);
				return false;
			}
			accept.lstHasItem.push_back(item);
		}
		//已获得成就
		else if (type == M_ACCEPT_TYPE_GAIN_ACHIEVE)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.achieveId = atoi(sonVecStr[1].c_str());
		}
		//以佩戴指定称号
		else if (type == M_ACCEPT_TYPE_DRESS_TITLE)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.titleId = atoi(sonVecStr[1].c_str());
		}
		//已激活坐骑
		else if (type == M_ACCEPT_TYPE_ACTIVE_HORSE)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.horseId = atoi(sonVecStr[1].c_str());
		}
		//已穿戴指定装备
		else if (type == M_ACCEPT_TYPE_DRESS_EQUIP)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.dressEquipId = atoi(sonVecStr[1].c_str());
		}
		//已激活指定时装
		else if (type == M_ACCEPT_TYPE_ACTIVE_FASHION)
		{
			if (sonVecStr[1] == "")
			{
				continue;
			}
			accept.activeFashionId = atoi(sonVecStr[1].c_str());
		}
		//指定属性区间
		else if (type == M_ACCEPT_TYPE_ATTR_RANGE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.attrId = atoi(sonVecStr[1].c_str());
			accept.attrMin = atoi(sonVecStr[2].c_str());
			accept.attrMax = atoi(sonVecStr[3].c_str());
		}
		//等级区间
		else if (type == M_ACCEPT_TYPE_LEVEL_RANGE)
		{
			if ( sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.minLevel = atoi(sonVecStr[2].c_str());
			accept.maxLevel = atoi(sonVecStr[3].c_str());
		}
		//指定采集副业等级区间
		else if (type == M_ACCEPT_TYPE_COLLECT_LEV_RANGE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.collLevType = atoi(sonVecStr[1].c_str());
			accept.collLevMin = atoi(sonVecStr[2].c_str());
			accept.collLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_MAKE_LEV_RANGE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.makeLevType = atoi(sonVecStr[1].c_str());
			accept.makeLevMin = atoi(sonVecStr[2].c_str());
			accept.makeLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_CAMP_KNIGHT)
		{
			for (int32_t i = 1; i < 6; ++i)
			{
				uint32_t knight = atoi(sonVecStr[i].c_str());
				if (knight > 0)
				{
					accept.setCampKnight.insert(knight);
				}
			}
		}
		else if (type == M_ACCEPT_TYPE_CAMP_OFFICIAL)
		{
			for (int32_t i = 1; i < 6; ++i)
			{
				uint32_t official = atoi(sonVecStr[i].c_str());
				if (official > 0)
				{
					accept.setCampOfficial.insert(official);
				}
			}
		}
		else if (type == M_ACCEPT_TYPE_GRID_LEV_RANGE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.gridLevId = atoi(sonVecStr[1].c_str());
			accept.gridLevMin = atoi(sonVecStr[2].c_str());
			accept.gridLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_ALL_REFINE_RANGE)
		{
			if (sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.allrefineLevMin = atoi(sonVecStr[2].c_str());
			accept.allrefineLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_ANY_REFINE_RANGE)
		{
			if (sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.anyrefineLevMin = atoi(sonVecStr[2].c_str());
			accept.anyrefineLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_SKILL_RANGE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "")
			{
				continue;
			}
			accept.skillLevId = atoi(sonVecStr[1].c_str());
			accept.skillLevMin = atoi(sonVecStr[2].c_str());
			accept.skillLevMax = atoi(sonVecStr[3].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_KILL_MONS)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalKillMonsId = atoi(sonVecStr[1].c_str());
			accept.totalKillMonsNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_LAST_ATTACK)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalLastKillId = atoi(sonVecStr[1].c_str());
			accept.totalLastKillNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_JOIN_ACT)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalJoinActId = atoi(sonVecStr[1].c_str());
			accept.totalJoinActNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_FINISH_ACT)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalFinishActId = atoi(sonVecStr[1].c_str());
			accept.totalFinishActNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_PASS_DUP)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalPassDupId = atoi(sonVecStr[1].c_str());
			accept.totalPassDupNum = atoi(sonVecStr[2].c_str());
		}
		/*else if (type == M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalDeputyCollectType = atoi(sonVecStr[1].c_str());
			accept.totalDeputyCollectNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalDeputyMakeType = atoi(sonVecStr[1].c_str());
			accept.totalDeputyMakeNum = atoi(sonVecStr[2].c_str());
		}*/
		else if (type == M_ACCEPT_TYPE_TOTAL_COLLECT)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalCollType = atoi(sonVecStr[1].c_str());
			accept.totalCollNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_MAKE)
		{
			if (sonVecStr[1] == "" || sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalMakeType = atoi(sonVecStr[1].c_str());
			accept.totalMakeNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalMakeGoldEquipNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_IDENTIFY)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalIdentifyNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalArenaSucessNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_PLAYER_DIE)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalDieNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_ONLINE)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalOnline = 60 * atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_KILL_ENEMY)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalKillEnemyNum = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalKillOtherCamp = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_CHARGE)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalCharge = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_GAIN_GOLD)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalGold = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_TREASURE)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalTreasure = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalPandosTrans = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_WORLD_CHAT)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalWorldChat = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalRefineSucess = atoi(sonVecStr[2].c_str());
		}
		else if (type == M_ACCEPT_TYPE_TOTAL_REFINE_FAIL)
		{
			if (sonVecStr[2] == "")
			{
				continue;
			}
			accept.totalRefineFail = atoi(sonVecStr[2].c_str());
		}
		else
		{
			MMOLOG_FMT_ERROR("MissionManager::ParseAcceptCond....unkown type...kind:%u,chapterid:%u,adventureid:%u,type:%u ", param.kind, param.chapterId, param.adventureId, type);
			return false;
		}

		//这里统一调用统计接口，统计哪些数据需要统计，统计模块只记录需要统计的数据
		g_GetOperateCfgMgr()->FilterAccept(accept);
	}
	return true;
}

bool MissionManager::ParseChapterCond(MissionChapterInfo &info, std::string strParam)
{
	SParaseAcceptParam param;
	param.kind = info.kind;
	param.chapterId = info.chapterId;
	return ParseAcceptCond(info.accept, strParam, param);
}

bool MissionManager::ParseTaskExecute(MissionInfo* pMissionInfo, std::string sExecute)
{
	if (nullptr == pMissionInfo)
	{
		return false;
	}

	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sExecute, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			return false;
		}

		//完成条件默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "" || sonVecStr[5] == "")
		{
			continue;
		}

		InterItemPair item;
		item.itemType = atoi(sonVecStr[0].c_str());
		item.itemId = atoi(sonVecStr[1].c_str());
		item.itemCount = atoi(sonVecStr[2].c_str());
		item.parma1 = atoi(sonVecStr[3].c_str());
		item.parma2 = atoi(sonVecStr[4].c_str());
		item.parma3 = atoi(sonVecStr[5].c_str());

		if (item.itemType <= MIN_MISSION_COND_TYPE)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute item.itemType <= MIN_MISSION_COND_TYPE ...missionId=%u, condtype:%d ", pMissionInfo->missionId,item.itemType);
			//return false;
		}

		if (MISSION_FINISH_TYPE_KILL_MONS == item.itemType
			|| MISSION_FINISH_TYPE_KILL_MONS_AREA == item.itemType
			)
		{
			uint32_t monsId = item.itemId;
			const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
			if (nullptr == pMonsCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find monster confg ...missionId=%u, condtype:%d, monsid:%u ", pMissionInfo->missionId, item.itemType, monsId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_COLLECT_ITEM == item.itemType
			|| MISSION_FINISH_TYPE_COLLECT_KILL_MONS == item.itemType
			|| MISSION_FINISH_TYPE_COLLECT_COLLECT == item.itemType
			|| MISSION_FINISH_TYPE_COLLECT_CLIENT == item.itemType
			|| MISSION_FINISH_TYPE_COLLECT_MONS == item.itemType
			|| MISSION_FINISH_TYPE_COLLECT_BUY == item.itemType
			)
		{
			uint32_t nItemId = item.itemId;
			const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(nItemId);
			if (nullptr == pItemCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find item confg ...missionId=%u, condtype:%d, itemid:%u ", pMissionInfo->missionId, item.itemType, nItemId);
				return false;
			}
			if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == item.itemType
				|| MISSION_FINISH_TYPE_COLLECT_MONS == item.itemType
				)
			{
				//打怪采集和采集怪物会有宝箱
				const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(item.parma1);
				if (nullptr == pMonsCfg)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find monster confg ...missionId=%u, condtype:%d, monsid:%u ", pMissionInfo->missionId, item.itemType, item.parma1);
					return false;
				}
				const BoxDropCfgInfo *pBoxCfg = g_GetBoxDropCfgTable()->GetBoxDropCfgInfo(item.parma2);
				if (nullptr == pBoxCfg)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find box confg ...missionId=%u, condtype:%d, boxid:%u ", pMissionInfo->missionId, item.itemType, item.parma2);
					return false;
				}

			/*	if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == item.itemType)
				{
					const DropDropCfgInfo *pDropCfg = g_GetDropDropCfgTable()->GetDropDropCfgInfo(item.parma2);
					if (nullptr == pDropCfg)
					{
						MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find drop confg ...missionId=%u, condtype:%d, dropid:%u ", pMissionInfo->missionId, item.itemType, item.parma2);
						return false;
					}
				}
				else if (MISSION_FINISH_TYPE_COLLECT_MONS == item.itemType)
				{
					const BoxDropCfgInfo *pBoxCfg = g_GetBoxDropCfgTable()->GetBoxDropCfgInfo(item.parma2);
					if (nullptr == pBoxCfg)
					{
						MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find box confg ...missionId=%u, condtype:%d, boxid:%u ", pMissionInfo->missionId, item.itemType, item.parma2);
						return false;
					}
				}*/
			}
		}
		else if (MISSION_FINISH_TYPE_PASS_DUP == item.itemType)
		{
			uint32_t dupId = item.itemId;
			const DuplicateDuplicateCfgInfo *pDupCfg = g_GetDuplicateDuplicateCfgTable()->GetDuplicateDuplicateCfgInfo(dupId);
			if (nullptr == pDupCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find duplicate confg ...missionId=%u, condtype:%d, dupid:%u ", pMissionInfo->missionId, item.itemType, dupId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_USE_ITEM == item.itemType
			|| MISSION_FINISH_TYPE_SUBMIT_ITEM == item.itemType
			)
		{
			uint32_t nItemId = item.itemId;
			const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(nItemId);
			if (nullptr == pItemCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find item confg ...missionId=%u, condtype:%d, itemid:%u ", pMissionInfo->missionId, item.itemType, nItemId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_SUBMIT_EQUIP == item.itemType)
		{
			uint32_t equipId = item.itemId;
			const EquipEquipCfgInfo *pEquipCfg = g_GetEquipEquipCfgTable()->GetEquipEquipCfgInfo(equipId);
			if (nullptr == pEquipCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find equip confg ...missionId=%u, condtype:%d, equipId:%u ", pMissionInfo->missionId, item.itemType, equipId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_IN_BUFF == item.itemType)
		{
			uint32_t buffId = item.itemId;
			const SkillBuffCfgInfo *pBuffCfg = g_GetSkillBuffCfgTable()->GetSkillBuffCfgInfo(buffId);
			if (nullptr == pBuffCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find buff confg ...missionId=%u, condtype:%d, buffId:%u ", pMissionInfo->missionId, item.itemType, buffId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_ANSEER == item.itemType)
		{
			uint32_t qustionId = item.itemId;
			const AnswerAnswerCfgInfo *pAnserCfg = g_GetAnswerAnswerCfgTable()->GetAnswerAnswerCfgInfo(qustionId);
			if (nullptr == pAnserCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find questionid confg ...missionId=%u, condtype:%d, qustionId:%u ", pMissionInfo->missionId, item.itemType, qustionId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_AREA == item.itemType)
		{
			uint32_t areaId = item.itemId;
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find area confg ...missionId=%u, condtype:%d, areaId:%u ", pMissionInfo->missionId, item.itemType, areaId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_USE_THING == item.itemType)
		{
			uint32_t thingMonsId = item.itemId;
			const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(thingMonsId);
			if (nullptr == pMonsCfg)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute can not find thing monster confg ...missionId=%u, condtype:%d, thingMonsId:%u ", pMissionInfo->missionId, item.itemType, thingMonsId);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_DEPUTY_COLLECT == item.itemType)
		{
			int32_t deputyCollType = item.itemId;
			/*
			ECollectDeputyType_None = 0,
			ECollectDeputyType_Herbs = 1,	//草药
			ECollectDeputyType_Mine = 2,	//矿石
			ECollectDeputyType_Fish = 3,	//钓鱼
			ECollectDeputyType_Peel = 4,	//剥皮
			//ECollectDeputyType_Task = 5,	//任务采集物件
			ECollectDeputyType_Limit,
			*/
			if (deputyCollType <= ECollectDeputyType_None || deputyCollType >= ECollectDeputyType_Limit)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute deputy collect type error ...missionId=%u, condtype:%d, deputyCollType:%d ", pMissionInfo->missionId, item.itemType, deputyCollType);
				return false;
			}

		}
		else if (MISSION_FINISH_TYPE_DEPUTY_MAKE == item.itemType)
		{
			int32_t deputyMakeType = item.itemId;
			/*
				EMakeDeputyType_None	= 0,
				EMakeDeputyType_Forge	= 1,	//锻造
				EMakeDeputyType_Sew		= 2,	//缝纫
				EMakeDeputyType_Smelt	= 3,	//冶金
				EMakeDeputyType_Cook	= 4,	//烹饪
				EMakeDeputyType_Medicine= 5,	//制药
				EMakeDeputyType_Starsoul= 6,	//星魂 以上为生活技能制造 以下为锻造炉制造
				EMakeDeputyType_Weapon	= 7,	//武器打造
				EMakeDeputyType_Armor	= 8,	//防具打造
				EMakeDeputyType_Jewelry = 9,	//首饰打造
				EMakeDeputyType_Limit,
			*/
			if (deputyMakeType <= EMakeDeputyType_None || deputyMakeType >= EMakeDeputyType_Limit)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute deputy make type error ...missionId=%u, condtype:%d, deputyMakeType:%d ", pMissionInfo->missionId, item.itemType, deputyMakeType);
				return false;
			}
		}
		else if (MISSION_FINISH_TYPE_OPTION == item.itemType)
		{
			//查询分支父任务下的子任务条件是否都存在
			SET_INT32 setChoice;
			setChoice.clear();
			if (item.itemId > 0)
			{
				setChoice.insert(item.itemId);
			}
			if (item.itemCount > 0)
			{
				setChoice.insert(item.itemCount);
			}
			if (item.parma1 > 0)
			{
				setChoice.insert(item.parma1);
			}
			if (item.parma2 > 0)
			{
				setChoice.insert(item.parma2);
			}
			if (item.parma3 > 0)
			{
				setChoice.insert(item.parma3);
			}
			if (setChoice.size() <= 0)
			{
				MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute.....setChoice.size() <= 0...missionId=%u ", pMissionInfo->missionId);
				return false;
			}
			SET_INT32::iterator iter = setChoice.begin();
			for (; iter != setChoice.end(); ++iter)
			{
				int32_t choiceid = (*iter);
				const ChoiceChoiceCfgInfo *pChoiceCfg = g_GetChoiceChoiceCfgTable()->GetChoiceChoiceCfgInfo(choiceid);
				if (nullptr == pChoiceCfg)
				{
					MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskExecute....nullptr == pChoiceCfg....missionId=%u , choiceid:%d ", pMissionInfo->missionId, choiceid);
					return false;
				}
			}
		}

		pMissionInfo->execute.items.push_back(item);
	}
	return true;
}

void MissionManager::ParseTaskRecereMove(MissionInfo* pMissionInfo, std::string sReceremove)
{
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("MissionManager::ParseTaskRecereMove...nullptr == pMissionInfo...");
		return;
	}
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sReceremove, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskRecereMove but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());
		

		pMissionInfo->receRemove.push_back(complex);
	}
}

void MissionManager::ParseTaskReceAdd(MissionInfo *pMissionInfo, std::string sReceAdd)
{
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("MissionManager::ParseTaskReceAdd...nullptr == pMissionInfo...");
		return;
	}
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sReceAdd, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskReceAdd but size not equal 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());


		pMissionInfo->receAdd.push_back(complex);

		if (complex.type == MISSION_AWARD_GOODS || complex.type == MISSION_AWARD_EQUIP) //装备道具奖励 
		{
			if (g_GetItemMgr()->IsTaskItem(complex.id))
			{
				pMissionInfo->receAddTask.push_back(complex);
			}
		}
	}
}

void MissionManager::ParseTaskSubAward(MissionInfo* pMissionInfo, std::string sSubAward)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sSubAward, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskSubAward but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "" || sonVecStr[5] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());
		complex.profession = atoi(sonVecStr[5].c_str());


		pMissionInfo->subAward.push_back(complex);
	}
}

void MissionManager::ParseTaskSubAwardRand(MissionInfo* pMissionInfo, std::string sSubAwardRand)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sSubAwardRand, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskSubAwardRand but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());


		pMissionInfo->subAwardRand.push_back(complex);
	}
}

void MissionManager::ParseTaskSubRemove(MissionInfo* pMissionInfo, std::string sSubRemove)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sSubRemove, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskSubRemove but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());


		pMissionInfo->subRemove.push_back(complex);
	}
}

void MissionManager::ParseTaskFailType(MissionInfo* pMissionInfo, std::string sFailType)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sFailType, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 2)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskFailType but size not equip 2 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有2个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "")
		{
			continue;
		}

		/*TaskFailType taskFailType;
		taskFailType.type = atoi(sonVecStr[0].c_str());
		taskFailType.val = atoi(sonVecStr[1].c_str());

		pMissionInfo->failType[taskFailType.type] = taskFailType;*/
	}
}

void MissionManager::ParseTaskFailRemove(MissionInfo* pMissionInfo, std::string sFailRemove)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(sFailRemove, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		std::vector<std::string> sonVecStr;
		CommonApi::SplitStr(vecStr[i], "=", &sonVecStr);

		if (sonVecStr.size() <= 0)
		{
			continue;
		}

		if (sonVecStr.size() != 6)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::ParseTaskFailType but size not equip 6 ...missionId=%u", pMissionInfo->missionId);
			break;
		}

		//默认有6个字段
		if (sonVecStr[0] == "" || sonVecStr[1] == "" || sonVecStr[2] == "" || sonVecStr[3] == "" || sonVecStr[4] == "")
		{
			continue;
		}

		TaskComplex complex;
		complex.type = atoi(sonVecStr[0].c_str());
		complex.id = atoi(sonVecStr[1].c_str());
		complex.value = atoi(sonVecStr[2].c_str());
		complex.time = atoi(sonVecStr[3].c_str());
		complex.bind = atoi(sonVecStr[4].c_str());


		//pMissionInfo->failRemove.push_back(complex);
	}
}

void MissionManager::ParseTaskReceEffect(MissionInfo* pMissionInfo, std::string receEffect)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(receEffect, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		uint32_t effectId = atoi(vecStr[i].c_str());
		if (effectId != 0)
		{
			pMissionInfo->triggerEffectIds.push_back(effectId);
		}
	}
}

void MissionManager::ParseTaskSubEffect(MissionInfo* pMissionInfo, std::string subEffect)
{
	std::vector<std::string> vecStr;
	//接取分隔符
	CommonApi::SplitStr(subEffect, "&", &vecStr);
	for (uint32_t i = 0; i < vecStr.size(); i++)
	{
		uint32_t effectId = atoi(vecStr[i].c_str());
		if (effectId != 0)
		{
			pMissionInfo->subEffectId.push_back(effectId);
		}
	}
}

MissionInfo* MissionManager::GetMissionCfgInfo(uint32_t missionId)
{
	MissionInfoMap::iterator iter = _missionInfoMap.find(missionId);
	return (iter != _missionInfoMap.end()) ? iter->second : nullptr;
}

const MissionChapterInfo* MissionManager::GetMissionChapterCfgInfo(uint32_t chapterId)
{
	MissionChapterInfoMap::iterator iter = _missionChapterMap.find(chapterId);
	return (iter != _missionChapterMap.end()) ? &iter->second : nullptr;
}

const DyMissionInfo* MissionManager::GetDyMissionCfgInfo(uint32_t missionId)
{
	DyMissionInfoMap::iterator iter = _dymissionInfoMap.find(missionId);
	return (iter != _dymissionInfoMap.end()) ? &iter->second : nullptr;
}
const DyConditionInfo*	MissionManager::GetDyConditionCfgInfo(uint32_t condId)
{
	DyCondtionInfoMap::iterator iter = _dycondtionInfoMap.find(condId);
	return (iter != _dycondtionInfoMap.end()) ? &iter->second : nullptr;
}
const SET_UINT32*	MissionManager::GetDyMissionLstByType(int32_t missionType)
{
	MAP_INT32_SET_UINT32::iterator iter = _dymissionTypeMap.find(missionType);
	return (iter != _dymissionTypeMap.end()) ? &iter->second : nullptr;
}

uint32_t MissionManager::GetDyTextId(uint64_t key)
{
	MAP_UINT64_SET_UINT32::iterator iter = _dymissionTextMap.find(key);
	if (iter == _dymissionTextMap.end())
	{
		return 0;
	}
	SET_UINT32 &setText = iter->second;
	int32_t isize = setText.size();
	if (isize <= 0)
	{
		return 0;
	}
	int32_t rnd = Random(1,isize);
	SET_UINT32::iterator iterText = setText.begin();
	for (; iterText != setText.end(); ++iterText)
	{
		--rnd;
		if (rnd <= 0)
		{
			return (*iterText);
		}
	}
	return 0;
}


bool MissionManager::ValidMissionType(int32_t missionType)	//是否是有效的任务类型
{
	SET_INT32::iterator iter = _setAllMissionType.find(missionType);
	return (iter != _setAllMissionType.end()) ? true : false;	
}

const SET_INT32& MissionManager::AllMissionType()//所有的任务类型
{
	return _setAllMissionType;
}

bool MissionManager::ValidCompleteType(int32_t completeType)//是否是有效的完成条件类型
{
	bool flag = false;
	switch (completeType)
	{
	case MISSION_FINISH_TYPE_KILL_MONS:					//杀怪					格式 101=怪物id=怪物数量=0=0=0
	case MISSION_FINISH_TYPE_KILL_MONS_AREA:			//杀怪追踪区域				格式 102=怪物id=怪物数量=追踪区域id=0=0（仅适用刷出怪物）
	case MISSION_FINISH_TYPE_TAKL:						//对话					格式 201=npcid=1=0=0=0
	case MISSION_FINISH_TYPE_COLLECT_ITEM:				//收集物品				格式 301=物品id=物品数量=0=0=0（背包中有足够数量，即完成任务）
	case MISSION_FINISH_TYPE_COLLECT_KILL_MONS:			//打怪收集				格式 302=物品id=物品数量=怪物id=宝箱id=追踪区域id
	case MISSION_FINISH_TYPE_COLLECT_COLLECT:			//采集收集				格式 303=物品id=物品数量=采集物id=0=0
	case MISSION_FINISH_TYPE_COLLECT_CLIENT:			//前端采集				格式 304=物品id=物品数量=采集物id=刷新区域id=0
	case MISSION_FINISH_TYPE_COLLECT_MONS:				//采集怪物				格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
	case MISSION_FINISH_TYPE_COLLECT_BUY:				//购买收集				格式 306=物品id=物品数量=NPC商店=0=0
	case MISSION_FINISH_TYPE_PASS_DUP:					//通关副本				格式 401=副本id=通关次数=0=0=0
	case MISSION_FINISH_TYPE_USE_ITEM:					//使用物品				格式 501=物品id=物品数量=使用区域=0=0
	case MISSION_FINISH_TYPE_SUBMIT_ITEM:				//提交物品				格式 502=物品id=物品数量=提交npc=0=0
	case MISSION_FINISH_TYPE_SUBMIT_EQUIP:				//提交装备				格式 503=装备id=装备数量=提交npc=0=0
	case MISSION_FINISH_TYPE_IN_BUFF:					//处于某种BUFF			格式 601=buffid=buff等级=0=0=0
	case MISSION_FINISH_TYPE_ANSEER:					//答题					格式 701=题目id=1=答题npc=0=0
	case MISSION_FINISH_TYPE_AREA:						//达到某区域				格式 801=区域id=次数=0=0=0
	case MISSION_FINISH_TYPE_USE_THING:					//使用物件				格式 901=怪物id=使用次数=0=0=0
	case MISSION_FINISH_TYPE_FINISH_ACTION:				//完成行为				格式 1001 = 行为ID = 行为次数 = 行为区域 = 0 = 0
	case MISSION_FINISH_TYPE_LEVEL:						//升级到多少级				格式 1101=目标级别=0=0=0=0
	case MISSION_FINISH_TYPE_OPTION:					//分支条件				格式 1201=choice表id字段=choice表id字段=choice表id字段=0=0
	case MISSION_FINISH_TYPE_GOD_LEVEL:					//神格升级				格式 10101=神格id=升级的等级=目标值=0=0
	case MISSION_FINISH_TYPE_REFINE:					//精炼					格式 10201=装备槽位id=精炼等级=0=0=0
	case MISSION_FINISH_TYPE_ADD_FRIEND:				//添加好友				格式 10301=0=添加好友次数=0=0=0
	case MISSION_FINISH_TYPE_DEPUTY_COLLECT:			//副业采集				格式 10401=副业采集类型=行为次数=0=0=0
	case MISSION_FINISH_TYPE_DEPUTY_MAKE:				//副业制造				格式 10501=副业制造类型=行为次数=0=0=0
	case MISSION_FINISH_TYPE_SKILL_LEVEL:				//技能升级				格式 10601=技能ID=指定等级=0=0=0
	case MISSION_FINISH_TYPE_ANY_GOD_LEVEL:				//任意神格升级				格式 10701=0=指定次数=0=0=0
	case MISSION_FINISH_TYPE_ANY_EQUIP_REFINE:			//任意装备精炼				格式 10801=0=指定次数=0=0=0
	case MISSION_FINISH_TYPE_ANY_STONE_INLAY:			//任意宝石镶嵌				格式 10901=0=指定数量=0=0=0
	case MISSION_FINISH_TYPE_RUNE_INLAY:				//符文镶嵌				格式 11001=符文类型=指定数量=0=0=0
	case MISSION_FINISH_TYPE_ATTR_POINT:				//属性洗点次数				格式 12001=0=指定次数=0=0=0
	case MISSION_FINISH_TYPE_ARENA:						//竞技场挑战次数			格式 13001=0=指定次数=0=0=0
	case MISSION_FINISH_TYPE_JOIN_CAMP:					//加入阵营				格式 14001=0=1=0=0=0
	case MISSION_FINISH_TYPE_JOIN_GUILD:				//加入工会				格式 15001=0=1=0=0=0
	case MISSION_FINISH_TYPE_ANY_GUILD_FIGHT_LEVEL:		//任意工会精修				格式 15101=0=行为次数=0=0=0
	case MISSION_FINISH_TYPE_ANY_RUN_BUSINESS:			//任意工会跑商				格式 15201=0=行为次数=0=0=0
	case MISSION_FINISH_TYPE_ANY_ESCORT:				//任意物资护送				格式 15301=0=行为次数=0=0=0
	{
		flag = true;
	}
	default:
		break;
	}
		
	return flag;
}
bool MissionManager::ValidDyCompleteType(int32_t completeType) //是否是有效的动态完成条件类型
{
	if ( MISSION_FINISH_TYPE_KILL_MONS == completeType
		|| MISSION_FINISH_TYPE_KILL_MONS_AREA == completeType
		|| MISSION_FINISH_TYPE_TAKL == completeType
		|| MISSION_FINISH_TYPE_COLLECT_ITEM == completeType
		|| MISSION_FINISH_TYPE_COLLECT_MONS == completeType
		|| MISSION_FINISH_TYPE_COLLECT_CLIENT == completeType
		|| MISSION_FINISH_TYPE_FINISH_ACTION == completeType
		|| MISSION_FINISH_TYPE_USE_THING == completeType
		|| MISSION_FINISH_TYPE_SUBMIT_ITEM == completeType
		|| MISSION_FINISH_TYPE_SUBMIT_EQUIP == completeType
		)
	{
		return true;
	}
	return false;
}
bool MissionManager::IsDyCompleteTypeNeedMap(int32_t completeType)
{
	//目前除了收集物品之外其他都需要配置地图
	if (MISSION_FINISH_TYPE_COLLECT_ITEM == completeType)
	{
		return false;
	}
	return true;
}

//完成任务触发外部系统（活跃度，成就等）
void MissionManager::TriggerOut(Player *pPlayer, uint32_t chapterId)
{
	if (nullptr == pPlayer)
	{
		return;
	}
	const MissionChapterInfo *pChapterCfg = GetMissionChapterCfgInfo(chapterId);
	if (nullptr == pChapterCfg)
	{
		return;
	}

	MAP_INT32_INT32 mapHuoyue;
	mapHuoyue.clear();
	VEC_INT32::const_iterator iter = pChapterCfg->vecOuttype.begin();
	for (; iter != pChapterCfg->vecOuttype.end(); ++iter)
	{
		int32_t otype = (*iter);
		MAP_INT32_INT32::const_iterator iterHuoyue = _triggerHuoyue.find(otype);
		if (iterHuoyue != _triggerHuoyue.end())
		{
			mapHuoyue[otype] = iterHuoyue->second;
		}
		
		//TODO 添加其他判断
	}
	
	if (mapHuoyue.size() > 0)
	{
		HuoYueDuPart *pHuoyuePart = dynamic_cast<HuoYueDuPart*>(pPlayer->GetPart(PART_HUOYUEDU));
		if (nullptr != pHuoyuePart)
		{
			MAP_INT32_INT32::iterator iterA = mapHuoyue.begin();
			for (; iterA != mapHuoyue.end(); ++iterA)
			{
				pHuoyuePart->AddHuoYueDuRecord((uint32_t)iterA->second);
			}			
		}
	}
	
}

const SET_UINT32* MissionManager::GetOptionSonMission(uint32_t parentMissionId)	//获取一个分支所有子任务的服任务
{
	MAP_UINT32_SET_UINT32::iterator iterOption = _mapOptionMission.find(parentMissionId);
	return (iterOption != _mapOptionMission.end()) ? &iterOption->second : nullptr;
}

bool MissionManager::IsOptionalParentMission(uint32_t parentMissionId)//是否是分支任务的父任务
{
	return (nullptr != GetOptionSonMission(parentMissionId));
}

bool MissionManager::IsOptionalSonMission(uint32_t parentMissionId, uint32_t sonMissionId)//是否是分支子任务
{
	const SET_UINT32 *pSon = GetOptionSonMission(parentMissionId);
	if (nullptr != pSon)
	{
		SET_UINT32::const_iterator iter = pSon->find(sonMissionId);
		return (iter != pSon->end()) ? true : false;
	}
	return false;
}

uint32_t MissionManager::GetBelonToOption(uint32_t sonMissionId) //获取一个分支子任务的服任务
{
	MAP_UINT32_UINT32::iterator iter = _mapBelongOption.find(sonMissionId);
	return (iter != _mapBelongOption.end()) ? iter->second : 0;
}

void MissionManager::CreateTabal(const uint32_t& zeroMissionId)
{
	Set tmpList;
	Set tmpQueue;
	std::queue<uint32_t> list;
	list.push(zeroMissionId);
	tmpQueue.insert(zeroMissionId);
	while (!list.empty())
	{
		uint32_t missionId = list.front();
		list.pop();
		tmpList.insert(missionId);
		tmpQueue.erase(missionId);
		MissionManager::Tabal::iterator at = _tabal.find(missionId);
		if (_tabal.end() == at)
		{
			MissionManager::Set l;
			l.insert(zeroMissionId);
			_tabal.insert(std::make_pair(missionId, l));
		}
		else
		{
			at->second.insert(zeroMissionId);
		}

		const SET_UINT32* pos = FindPostList(missionId);
		if (nullptr == pos)
		{
			continue;
		}

		if (pos->size() == 1)
		{
			uint32_t id = *pos->begin();
			if (0 == tmpList.count(id) && 0 == tmpQueue.count(id))
			{
				list.push(id);
				tmpQueue.insert(id);
			}
		}
		else
		{
			//uint32 n = 0;
			for (SET_UINT32::const_iterator i = pos->begin(); i != pos->end(); ++i)
			{
				uint32_t id = *i;
				if (0 == tmpList.count(id) && 0 == tmpQueue.count(id))
				{
					list.push(id);
					tmpQueue.insert(id);
				}
			}
		}

	}
}

const SET_UINT32* MissionManager::FindPostList(const uint32_t& preCon)
{
	MissionListMap::iterator ite = _postList.find(preCon);
	if (ite != _postList.end())
	{
		return &ite->second;
	}

	return nullptr;
}

MissionManager::Set* MissionManager::FindHeadList(const uint32_t& missionId)
{
	MissionManager::Tabal::iterator iter = _tabal.find(missionId);
	if (_tabal.end() != iter)
	{
		return &iter->second;
	}
	/*else
	{
		MissionManager::Set list;
		return list;
	}*/
	return nullptr;
}

MissionInfo* MissionManager::FindMissionInfoById(const uint32_t& missionId)
{
	MissionInfo * missionInfoPtr = NULL;

	MissionInfoMap::iterator ite = _missionInfoMap.find(missionId);
	if (ite != _missionInfoMap.end())
	{
		missionInfoPtr = ite->second;
	}

	return missionInfoPtr;
}

MissionManager::WithoutPreConMissionsMap& MissionManager::FindMissionListWithoutPreCon()
{
	return _withoutPreConMissionsList;
}

uint32_t MissionManager::BountyFreshItemID()	//赏金任务刷新道具ID
{
	return m_BountyFreshItemID;
}

uint32_t MissionManager::BountyMaxAcceptNum()	//赏金任务周期内最大接取次数
{
	return m_BountyMaxAcceptNum;
}

uint32_t MissionManager::GetFirstChapter(int32_t camp, int32_t race)
{
	const TasktrackerFirstChapterCfgMap *pMap = g_GetTasktrackerFirstChapterCfgTable()->GetTasktrackerFirstChapterCfgMap();
	if (nullptr == pMap)
	{
		return 0;
	}
	TasktrackerFirstChapterCfgMap::const_iterator iter = pMap->begin();
	for (; iter != pMap->end(); ++iter)
	{
		if (iter->second.campId == camp && iter->second.raceId == race)
		{
			return iter->second.firstChapterId;
		}
	}
	return 0;
}

///////////////////////////////////新任务接口///////////////////////////////////////
//获取可接任务列表
int32_t	MissionManager::OnCanAccept(Player* pPlayer, SET_UINT32& missionList, int32_t recvType /*= M_RECEIVE_TYPE_USER*/)
{
	/*MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	for (SET_UINT32::iterator iter = pMissionPart->_setEffPreMission.begin(); iter != pMissionPart->_setEffPreMission.end(); ++iter)
	{
		//查找该任务的后置任务列表
		uint32_t preMissionId = (*iter);
		const SET_UINT32* post = g_GetMissionManager()->FindPostList(preMissionId);
		if (nullptr == post)
		{
			continue;
		}

		for (SET_UINT32::const_iterator postIte = post->begin(); postIte != post->end(); ++postIte)
		{
			missionList.insert(*postIte);
		}
	}
	//没有前置任务的任务列表
	uint32_t level = pPlayer->GetAttr(C_LEVEL);
	MissionManager::WithoutPreConMissionsMap& withoutPreM = g_GetMissionManager()->FindMissionListWithoutPreCon(); //获取没有前置任务的列表
	MissionManager::WithoutPreConMissionsMap::iterator withoutPreIter = withoutPreM.find(level);
	if (withoutPreIter != withoutPreM.end())
	{
		for (MissionManager::Set::iterator witIte = withoutPreIter->second.begin(); witIte != withoutPreIter->second.end(); ++witIte)
		{
			missionList.insert(*witIte);
		}
	}

	//是否可接
	SET_UINT32::iterator iterAccept = missionList.begin();
	while (iterAccept != missionList.end())
	{
		uint32_t missionId = (*iterAccept);
		if (RET_SUCCESS != CanAccept(pPlayer, missionId, recvType))
		{
			iterAccept = missionList.erase(iterAccept);
			continue;
		}
		++iterAccept;
	}*/
	return RET_SUCCESS;
}
int32_t MissionManager::CanAccept(Player *pPlayer, uint32_t missionId, bool reacceptFlag)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	MissionInfo *pMissionInfo = GetMissionCfgInfo(missionId);
	return CanAccept(pPlayer, pMissionInfo, reacceptFlag);
}

int32_t MissionManager::CanAccept(Player *pPlayer, MissionInfo *pMissionInfo, bool reacceptFlag)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	if (nullptr == pMissionInfo)
	{
		return RET_CONFIG_ERROR;
	}	
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	//是否接取过该任务
	if (pMissionPart->HaveAccpet(pMissionInfo->missionId))
	{
		return RET_MISSION_HAVE_ACCEPT;
	}
	//是否已经接取过该章节的任务
	if (pMissionPart->HaveAcceptChapter(pMissionInfo->chapterId))
	{
		return RET_MISSION_HAS_ACCEPT_CHAPTER;
	}
	//流放之地任务需要校验下当前地图
	if (MISSION_TYPE_ID_BANISH == pMissionInfo->kind)
	{
		int32_t mapId = (int32_t)pPlayer->GetMapId();
		const ConstantConstantCfgInfo *pBanishMap = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_ClearPoint_Jail);
		if (nullptr != pBanishMap && pBanishMap->constantdata != mapId)
		{
			//地图限制
			return RET_MISSION_MAPID_LIMIT;
		}
	}
	else if (MISSION_TYPE_ID_TRUNK == pMissionInfo->kind)
	{
		//主线任务验证下是否已经接取过主线任务
		if (pMissionPart->MissionNumByType(MISSION_TYPE_ID_TRUNK) > 0)
		{
			return RET_MISSION_HAVE_TYPE_ACCEPT;
		}
	}
	//章节是否已经提交
	if (pMissionPart->HaveChapterSubmit(pMissionInfo->chapterId))
	{
		return RET_MISSION_CHAPTER_ALREADY_SUBMIT;
	}
	//章节的第一个任务，并且不是重新接取，需要验证章节接取条件
	if (pMissionInfo->isFirst && !reacceptFlag)
	{
		const MissionChapterInfo *pChapterCfg = GetMissionChapterCfgInfo(pMissionInfo->chapterId);
		if (nullptr == pChapterCfg)
		{
			return RET_CONFIG_ERROR;
		}
		SCanAcceptParam param;
		param.missionId = pMissionInfo->missionId;
		param.chapterId = pMissionInfo->chapterId;

		return CanAccept(pPlayer, pChapterCfg->accept, param);
	}

	return RET_SUCCESS;
}

int32_t  MissionManager::CanAccept(Player *pPlayer, const AcceptInfo &cond, SCanAcceptParam &param)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pMissionPart...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	PackagePart *pPackage = dynamic_cast<PackagePart*>(pPlayer->GetPart(PART_PACKAGE));
	if (nullptr == pPackage)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pPackage...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	DeputyPart *pDeputyPart = dynamic_cast<DeputyPart*>(pPlayer->GetPart(PART_DEPUTY));
	if (nullptr == pDeputyPart)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pDeputyPart...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	GodPart *pGodPart = dynamic_cast<GodPart*>(pPlayer->GetPart(PART_GOD));
	if (nullptr == pGodPart)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pGodPart...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	AchievementPart *pAchievePart = dynamic_cast<AchievementPart*>(pPlayer->GetPart(PART_ACHIEVEMENT));
	if (nullptr == pAchievePart)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pAchievePart...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	OperateLimitPart *pOperateLimitPart = dynamic_cast<OperateLimitPart*>(pPlayer->GetPart(PART_OPERATELIMIT));
	if (nullptr == pOperateLimitPart)
	{
		LogErrFmtPrint("MissionManager::CanAccept...nullptr == pOperateLimitPart...cid:%lu ", pPlayer->GetCid());
		return RET_FAIL;
	}
	//前置章节判断（或关系）
	if (cond.setPreOrChapter.size() > 0)
	{
		bool haveSubmit = false;
		SET_UINT32::const_iterator iterOr = cond.setPreOrChapter.begin();
		for (; iterOr != cond.setPreOrChapter.end(); ++iterOr)
		{
			const uint32_t id = (*iterOr);
			if (pMissionPart->HaveChapterSubmit(id))
			{
				haveSubmit = true;
				break;
			}
		}
		if (!haveSubmit)
		{
			return RET_MISSION_GROUP_LIMIT;
		}
	}
	//职业
	if (cond.profession > 0 && pPlayer->GetAttr(C_PROF) != cond.profession)
	{
		return RET_MISSION_PROFESSION_LIMIT;
	}
	//性别
	if (cond.sex > 0 && pPlayer->GetAttr(C_GENDER) != cond.sex)
	{
		return RET_MISSION_SEX_LIMIT;
	}
	//阵营
	if (cond.camp > 0 && pPlayer->GetAttr(C_CAMP_ID) != cond.camp)
	{
		return RET_MISSION_CAMP_LIMIT;
	}
	//种族
	if (cond.race > 0 && pPlayer->GetAttr(C_RACE) != cond.race)
	{
		return RET_MISSION_RACE_LIMIT;
	}
	//互斥章节
	if (cond.setMutChapter.size() > 0)
	{
		SET_UINT32::const_iterator iter = cond.setMutChapter.begin();
		for (; iter != cond.setMutChapter.end(); ++iter)
		{
			const uint32_t id = (*iter);//已接取和已提交的章节都是互斥的
			if (pMissionPart->HaveAcceptChapter(id) || pMissionPart->HaveChapterSubmit(id))
			{
				return RET_MISSION_MUTEX_LIMIT;
			}
		}
	}
	//前置章节判断（与关系）
	if (cond.setPreAndChapter.size() > 0)
	{
		bool haveSubmit = true;
		SET_UINT32::const_iterator iterAnd = cond.setPreAndChapter.begin();
		for (; iterAnd != cond.setPreAndChapter.end(); ++iterAnd)
		{
			const uint32_t id = (*iterAnd);
			if (!pMissionPart->HaveChapterSubmit(id))
			{
				haveSubmit = false;
				break;
			}
		}
		if (!haveSubmit)
		{
			return RET_MISSION_GROUP_LIMIT;
		}
	}
	//工会
	if (cond.guild > 0 && pPlayer->GetAttr(C_UNION_ID) <= 0)
	{
		return RET_MISSION_GUILD_LIMIT;
	}
	//组队
	if (cond.team > 0 && pPlayer->GetAttr(C_TEAM_ID) <= 0)
	{
		return RET_MISSION_TEAM_LIMIT;
	}
	//处于区域内
	if (cond.inarea > 0)
	{
		Scene *pScene = pPlayer->GetScene();
		Point3<float> pos = pPlayer->GetPos();
		if (nullptr == pScene || !pScene->InArea(cond.inarea, pos))
		{
			return RET_MISSION_INAREA_LIMIT;
		}
	}
	//处于地图内
	if (cond.inmap > 0 && pPlayer->GetMapId() != cond.inmap)
	{
		return RET_MISSION_MAPID_LIMIT;
	}
	//位面限制
	if (cond.plane >= 0)
	{
		if (0 == cond.plane)
		{
			if (pPlayer->GetPlaneID() > 0)
			{
				return RET_MISSION_PLANE_LIMIT;
			}
		}
		else if (pPlayer->GetPlaneID() <= 0)
		{
			return RET_MISSION_PLANE_LIMIT;
		}
		else
		{
			CPlane *pPlane = g_GetPlaneMgr()->GetPlane(pPlayer->GetPlaneID());
			if (nullptr == pPlane || pPlane->GetPlaneConfigID() != (uint32_t)cond.plane)
			{
				return RET_MISSION_PLANE_LIMIT;
			}
		}
	}	
	//开启时间
	if (cond.openHour >= 0 && cond.openMin >= 0 && cond.lastMin > 0)
	{
		//先判断当前时间段
		uint64_t curTime = g_GetGlobalServerTime()->UnixSec();
		uint64_t dayZero = TimeUtility::DayZero(curTime);
		uint64_t openBeginTime = dayZero + cond.openHour * 3600 + cond.openMin * 60;
		uint64_t openEndTime = openBeginTime + cond.lastMin * 60;
		if (curTime < openBeginTime || curTime > openEndTime)
		{
			return RET_MISSION_OPEN_TIME_LIMIT;
		}
		//星期几校验
		uint32_t weekDay = TimeUtility::GetLocalWeekDay();
		if (weekDay == 0)
		{
			weekDay = 7;
		}
		SET_INT32::const_iterator iter = cond.setOpenWeek.find(weekDay);
		if (iter == cond.setOpenWeek.end())
		{
			return RET_MISSION_OPEN_TIME_LIMIT;
		}
	}

	//已携带物品
	if (cond.lstHasItem.size() > 0)
	{
		LIST_ITEM lstItem = cond.lstHasItem;
		if (!pPackage->HasItem(lstItem))
		{
			return RET_MISSION_HAS_ITEM_LIMIT;
		}		
	}
	//已获得的成就
	if (cond.achieveId > 0 && !pAchievePart->FinishAchieve(cond.achieveId))
	{
		return RET_MISSION_ACHIEVE_LIMIT;
	}
	//已佩戴指定称号
	if (cond.titleId > 0 && pPlayer->GetAttr(C_USE_TITLE) != cond.titleId)
	{
		return RET_MISSION_DRESS_TITLE_LIMIT;
	}
	//已激活指定坐骑
	if (cond.horseId > 0)
	{

	}
	//已穿戴指定装备
	if (cond.dressEquipId > 0 && !pPackage->IsEquipDress(cond.dressEquipId))
	{
		return RET_MISSION_DRESS_EQUIP_LIMIT;
	}
	//已激活指定时装
	if (cond.activeFashionId > 0 && !pPackage->IsFashionDress(cond.activeFashionId))
	{
		return RET_MISSION_ACTIVE_FASHION_LIMIT;
	}
	//属性区间范围
	if (cond.attrId > 0)
	{
		if (pPlayer->GetAttr(cond.attrId) < cond.attrMin || pPlayer->GetAttr(cond.attrId) > cond.attrMax)
		{
			return RET_MISSION_ATTR_LIMIT;
		}
	}
	//等级限制
	if (cond.minLevel > 0 && cond.maxLevel > 0)
	{
		if (pPlayer->GetAttr(C_LEVEL) < cond.minLevel || pPlayer->GetAttr(C_LEVEL) > cond.maxLevel)
		{
			return RET_MISSION_LEVEL_ERROR;
		}
	}
	//指定采集副业等级区间
	if (cond.collLevType > 0)
	{
		uint32_t lev = pDeputyPart->GetCollectSkillLvl((ECollectDeputyType)cond.collLevType);
		if (lev < cond.collLevMin || lev > cond.collLevMax)
		{
			return RET_MISSION_COLLECT_LEVEL_LIMIT;
		}
	}	
	//指定制造副业等级区间
	if (cond.makeLevType > 0)
	{
		uint32_t lev = pDeputyPart->GetMakeSkillLvl((EMakeDeputyType)cond.makeLevType);
		if (lev < cond.makeLevMin || lev > cond.makeLevMax)
		{
			return RET_MISSION_MAKE_LEVEL_LIMIT;
		}
	}
	//阵营爵位
	if (cond.setCampKnight.size() > 0)
	{
		uint32_t campKnight = pPlayer->GetAttr(C_KNIGHT);
		SET_UINT32::const_iterator iter = cond.setCampKnight.find(campKnight);
		if (iter == cond.setCampKnight.end())
		{
			return RET_MISSION_PEERAGES_LIMIT;
		}
	}
	//阵营官职
	if (cond.setCampOfficial.size() > 0 )
	{
		uint32_t campOfficial = pPlayer->GetAttr(C_OFFICIAL);
		SET_UINT32::const_iterator iter = cond.setCampOfficial.find(campOfficial);
		if (iter == cond.setCampOfficial.end())
		{
			return RET_MISSION_OFFICIAL_LIMIT;
		}
	}
	//指定神格等级区间
	if (cond.gridLevId > 0)
	{
		uint32_t lev = pGodPart->GetGodLevel(cond.gridLevId);
		if (lev < cond.gridLevMin || lev > cond.gridLevMax)
		{
			return RET_MISSION_GOD_LEVEL_LIMIT;
		}
	}

	//所有身上装备精炼之和
	if (cond.allrefineLevMin > 0 && cond.allrefineLevMax > 0)
	{
		uint32_t lev = pPackage->GetTolRefineLvl();
		if (lev < cond.allrefineLevMin || lev > cond.allrefineLevMax)
		{
			return RET_MISSION_REFINE_LEVEL_LIMIT;
		}
	}
	//任一身上精炼满足等级区间
	if (cond.anyrefineLevMin > 0 && cond.anyrefineLevMax > 0)
	{
		if (!pPackage->RefineInLvl(cond.anyrefineLevMin, cond.anyrefineLevMax))
		{
			return RET_MISSION_REFINE_LEVEL_LIMIT;
		}
	}
	//指定技能等级技能
	if (cond.skillLevId > 0)
	{
		SkillPart *pSkillPart = dynamic_cast<SkillPart*>(pPlayer->GetPart(PART_SKILL));
		if (nullptr == pSkillPart)
		{
			return RET_MISSION_SKILL_LEVEL_LIMIT;
		}
		uint32_t skillLev = pSkillPart->GetSkillLev(cond.skillLevId);
		if (skillLev < cond.skillLevMin || skillLev > cond.skillLevMax)
		{
			return RET_MISSION_SKILL_LEVEL_LIMIT;
		}
	}
	//累计击杀指定怪物
	if (cond.totalKillMonsId > 0)
	{
		if ((uint64_t)cond.totalKillMonsNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_MONS, cond.totalKillMonsId))
		{
			return RET_MISSION_KILL_MONS_NUM_LIMIT;
		}
	}
	//累计击杀指定怪物(最后一击)
	if (cond.totalLastKillId > 0)
	{
		if ((uint64_t)cond.totalLastKillNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_LAST_ATTACK, cond.totalLastKillId))
		{
			return RET_MISSION_KILL_MONS_NUM_LIMIT;
		}
	}
	//累计参加指定活动
	if (cond.totalJoinActId > 0)
	{
		if ((uint64_t)cond.totalJoinActNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_JOIN_ACT, cond.totalJoinActId))
		{
			return RET_MISSION_ATTEND_ACT_NUM_LIMIT;
		}
	}
	//累计完成指定活动
	if (cond.totalFinishActId > 0)
	{
		if ((uint64_t)cond.totalFinishActNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_FINISH_ACT, cond.totalFinishActId))
		{
			return RET_MISSION_FINISH_ACT_NUM_LIMIT;
		}
	}
	//累计通关指定副本
	if (cond.totalPassDupId > 0)
	{
		if ((uint64_t)cond.totalPassDupNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_PASS_DUP, cond.totalPassDupId))
		{
			return RET_MISSION_PASS_DUP_NUM_LIMIT;
		}
	}
	//累计收集副业行为
	if (cond.totalDeputyCollectType > 0)
	{
		/*if ((uint64_t)cond.totalDeputyCollectNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT, cond.totalDeputyCollectType))
		{
			return RET_MISSION_COLLECT_ACTION_LIMIT;
		}*/
	}
	//累计副业行为
	if (cond.totalDeputyMakeType > 0)
	{
		/*if ((uint64_t)cond.totalDeputyMakeNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE, cond.totalDeputyMakeType))
		{
			return RET_MISSION_MAKE_ACTION_LIMIT;
		}*/
	}
	//累计采集成功采集
	if (cond.totalCollType > 0)
	{
		if ((uint64_t)cond.totalCollNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_COLLECT, cond.totalCollType))
		{
			return RET_MISSION_COLLECT_NUM_LIMIT;
		}
	}
	//累计制造成功采集
	if (cond.totalMakeType > 0)
	{
		if ((uint64_t)cond.totalMakeNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE, cond.totalMakeType))
		{
			return RET_MISSION_MAKE_NUM_LIMIT;
		}
	}
	//累计打造金色装备数量
	if (cond.totalMakeGoldEquipNum > 0)
	{
		if ((uint64_t)cond.totalMakeGoldEquipNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP))
		{
			return RET_MISSION_MAKE_EQUIP_NUM_LIMIT;
		}
	}
	//累计鉴定次数
	if (cond.totalIdentifyNum > 0)
	{
		if ((uint64_t)cond.totalIdentifyNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_IDENTIFY))
		{
			return RET_MISSION_IDENTIFY_NUM_LIMIT;
		}
	}
	//累计竞技场成功次数
	if (cond.totalArenaSucessNum > 0)
	{
		if ((uint64_t)cond.totalArenaSucessNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS))
		{
			return RET_MISSION_ARENA_NUM_LIMIT;
		}
	}
	//玩家死亡次数
	if (cond.totalDieNum > 0)
	{
		if ((uint64_t)cond.totalDieNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_PLAYER_DIE))
		{
			return RET_MISSION_DIE_NUM_LIMIT;
		}
	}
	//累计在线时长,单位：秒
	if (cond.totalOnline > 0)
	{
		uint64_t loginTime = pPlayer->GetLoginTime();
		uint64_t onlineSec = pPlayer->GetOnlineSec() + g_GetGlobalServerTime()->UnixSec() - loginTime;
		if ((uint64_t)cond.totalOnline < onlineSec)
		{
			return RET_MISSION_ONLINE_TIME_LIMIT;
		}
	}
	//累计击杀仇人次数
	if (cond.totalKillEnemyNum > 0)
	{
		if ((uint64_t)cond.totalKillEnemyNum > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_ENEMY))
		{
			return RET_MISSION_KILL_ENEMY_NUM_LIMIT;
		}
	}
	//累计击杀敌对阵营玩家
	if (cond.totalKillOtherCamp > 0)
	{
		if ((uint64_t)cond.totalKillOtherCamp > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_ENEMY))
		{
			return RET_MISSION_KILL_OTHER_CAMP_LIMIT;
		}
	}
	//累计充值指定金额
	if (cond.totalCharge > 0)
	{
		if ((uint64_t)cond.totalCharge > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_CHARGE))
		{
			return RET_MISSION_CHARGE_LIMIT;
		}
	}
	//累计获得金币数量
	if (cond.totalGold > 0)
	{
		if ((uint64_t)cond.totalGold > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_GAIN_GOLD))
		{
			return RET_MISSION_GOLD_LIMIT;
		}
	}
	//累计挖宝次数
	if (cond.totalTreasure > 0)
	{
		if ((uint64_t)cond.totalTreasure > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_TREASURE))
		{
			return RET_MISSION_TREASURE_NUM_LIMIT;
		}
	}
	//累计星盘传送次数
	if (cond.totalPandosTrans > 0)
	{
		if ((uint64_t)cond.totalPandosTrans > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS))
		{
			return RET_MISSION_PANDOS_TRANS_NUM_LIMIT;
		}
	}
	//累计世界聊天次数
	if (cond.totalWorldChat > 0)
	{
		if ((uint64_t)cond.totalWorldChat > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_WORLD_CHAT))
		{
			return RET_MISSION_WORLD_CHAT_NUM_LIMIT;
		}
	}
	//累计精炼成功次数
	if (cond.totalRefineSucess > 0)
	{
		if ((uint64_t)cond.totalRefineSucess > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS))
		{
			return RET_MISSION_REFINE_NUM_LIMIT;
		}
	}
	//累计精炼失败次数
	if (cond.totalRefineFail > 0)
	{
		if ((uint64_t)cond.totalRefineFail > pOperateLimitPart->GetStatisticData(M_ACCEPT_TYPE_TOTAL_REFINE_FAIL))
		{
			return RET_MISSION_REFINE_NUM_LIMIT;
		}
	}
	return RET_SUCCESS;
}

//阵营任务判断工会和队伍
int32_t MissionManager::CanAcceptEx(Player *pPlayer, MissionInfo *pMissionInfo)
{
	if (nullptr == pPlayer || nullptr == pMissionInfo)
	{
		return RET_SUCCESS;
	}
	if (CAMP_CHANGE_LIGHT_TASKID == pMissionInfo->missionId
		|| CAMP_CHANGE_DARK_TASKID == pMissionInfo->missionId
		)
	{
		if (pPlayer->GetAttr(C_TEAM_ID) > 0)
		{
			return RET_MISSION_MUST_QUIT_TEAM;
		}
		else if (pPlayer->GetAttr(C_UNION_ID) > 0)
		{
			return RET_MISSION_MUST_QUIT_UNION;
		}
	}
	return RET_SUCCESS;
}

int32_t MissionManager::CanAcceptDy(Player *pPlayer, uint32_t dyCfgId)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	const DyMissionInfo *pDyMissionInfo = GetDyMissionCfgInfo(dyCfgId);
	return CanAcceptDy(pPlayer, pDyMissionInfo);
}

int32_t MissionManager::CanAcceptDy(Player *pPlayer, const DyMissionInfo *pDyMissionInfo)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	const TasktypeTasktypeCfgInfo *pMissionTypeInfo = g_GetTasktypeTasktypeCfgTable()->GetTasktypeTasktypeCfgInfo(pDyMissionInfo->kind);
	if (nullptr == pMissionTypeInfo)
	{
		return RET_FAIL;
	}
	uint32_t level = pPlayer->GetAttr(C_LEVEL);
	if ((int32_t)level < pMissionTypeInfo->minlv)
	{
		return RET_MISSION_OPEN_LEVEL_LIMIT;
	}
	if (pMissionPart->MissionNumByType(pDyMissionInfo->kind) >= pMissionTypeInfo->receiveCount)
	{
		return RET_MISSION_PERIOD_ONCE_EXIST_NUM_LIMIT;
	}
	if (level < pDyMissionInfo->minLev || level > pDyMissionInfo->maxLev)
	{
		return RET_MISSION_LEVEL_ERROR;
	}
	int32_t maxCount = DyMaxCount(pDyMissionInfo->kind, level);
	if (maxCount != MISSION_INFINITE_COUNT)
	{
		if (pMissionPart->HaveFinishNumByType(pDyMissionInfo->kind) >= maxCount)
		{
			return RET_MISSION_PERIOD_FINISH_NUM_LIMIT;
		}
	}
	if (!pMissionPart->MissionOpen(pDyMissionInfo->kind))
	{
		return RET_MISSION_NOT_OPEN;
	}
	if (MISSION_TYPE_ID_BOUNTY == pDyMissionInfo->kind)
	{
		//赏金任务需要判断周期内最大接取次数
		if (pMissionPart->_bountyAccetpNum >= BountyMaxAcceptNum())
		{
			return RET_MISSION_HAVE_ACCEPT_NUMBER_LIMIT;
		}
	}	
	return RET_SUCCESS;
}

int32_t MissionManager::CanAcceptDy(Player *pPlayer, MissionTrack *pMissionTrack)
{
	if (nullptr == pPlayer || nullptr == pMissionTrack)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	uint32_t missionId = pMissionTrack->missionId;
	uint32_t dymissionId = pMissionTrack->dynamicId;
	if (!pMissionPart->ValidDyMissionId(dymissionId))
	{
		return RET_FAIL;
	}
	if (pMissionPart->HaveAccpet(dymissionId))
	{
		return RET_MISSION_HAVE_ACCEPT;
	}
	return CanAcceptDy(pPlayer, missionId);
}
//GM接取任务
int32_t MissionManager::OnGMAccept(Player* pPlayer, uint32_t missionId, bool notify)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnAccept nullptr == pPlayer", missionId);
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnGMAccept nullptr == pMissionPart", missionId);
		return RET_FAIL;
	}
	//接取任务
	MissionInfo* pMissionInfo = GetMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnGMAccept Have Not MissionID=%u Config, Please Check Mission Config", missionId);
		return RET_MISSION_NOT_EXIST;
	}
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(missionId);
	if (iter != pMissionPart->_playerTrackMissionMap.end())
	{
		return RET_MISSION_HAVE_ACCEPT;
	}
	//
	MissionTrack* pMissionTrack = AllocMissionTrack();
	if (nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR("[logic] OnGMAccept MissionID=%u, Allcol MissionTrackObj is nullptr", missionId);
		return RET_FAIL;
	}
	//填充完成条件信息 多任务条件
	std::vector<ItemInfo> conds;
	conds.clear();
	if (RET_SUCCESS != OnExtractCond(pPlayer, pMissionInfo, conds))
	{
		FreeMissionTrack(pMissionTrack);
		MMOLOG_FMT_ERROR("[logic] OnGMAccept MissionID=%u, OnExtractCond failed...", missionId);
		return RET_FAIL;
	}
	/*//扣除中间道具
	if (!g_GetMissionManager()->RemoveReward(pPlayer, pMissionInfo->receRemove))
	{
		FreeMissionTrack(pMissionTrack);
		return RET_MISSION_ATTR_LIMIT;
	}

	//接取任务获取中间道具
	g_GetMissionManager()->AddReward(pPlayer, pMissionInfo->receAdd);*/
	//填充任务数据信息
	pMissionTrack->missionId = missionId;
	pMissionTrack->dynamicId = missionId; //主支线任务动态任务ID和配置ID一样
	pMissionTrack->acceptMissionTime = Time::Now().sec();
	pMissionTrack->status = MISSION_E_ACCEPTED;
	pMissionTrack->items = conds;
	//添加到可接列表中来
	pMissionPart->_playerTrackMissionMap[pMissionTrack->dynamicId] = pMissionTrack;

	//任务接取触发效果
	for (uint32_t i = 0; i < pMissionInfo->triggerEffectIds.size(); i++)
	{
		if (pMissionInfo->triggerEffectIds[i] > 0)
		{
			g_GetEffectMgr()->OnEffect(pPlayer, pMissionInfo->triggerEffectIds[i]);
		}
	}

	//判断任务是否完成
	bool isCompletedFlag = true;
	for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
	{
		if (!pMissionTrack->items[i].completedFlag)
		{
			isCompletedFlag = false;
			break;
		}
	}
	//如果已经完成
	if (isCompletedFlag)
	{
		//如果可以完成
		pMissionTrack->status = MISSION_E_COMPLETION;
	}
	else //没有完成的条件才会注册事件
	{
		//添加任务掉落处理
		OnAddMissionDrop(pPlayer->GetCid(), pMissionPart, pMissionTrack, pMissionInfo->progressLev);
		//注册事件
		for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
		{
			if (!pMissionTrack->items[i].completedFlag)
			{
				int32_t relEvent = MISSION_COND_TYPE_TO_EVENT(pMissionTrack->items[i].type);
				pMissionPart->RegisterEvent(relEvent, pMissionTrack->dynamicId, pMissionInfo->progressLev);
			}
		}
	}
	LogDebugFmtPrint("MissionManager::OnGMAccept...cid:%lu,missionid:%u,chapterid:%u,camp:%d,race:%d", pPlayer->GetCid(), missionId, pMissionInfo->chapterId, (int32_t)pPlayer->GetCampId(), (int32_t)pPlayer->GetAttr(C_RACE));

	//如果要通知客户端
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(missionId);
	}

	return RET_SUCCESS;
}
//接取任务
int32_t MissionManager::OnAccept(Player* pPlayer, uint32_t missionId,bool notify, bool reacceptFlag /*= false*/)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnAccept nullptr == pPlayer", missionId);
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnAccept nullptr == pMissionPart", missionId);
		return RET_FAIL;
	}
	//接取任务
	MissionInfo* pMissionInfo = GetMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnAccept Have Not MissionID=%u Config, Please Check Mission Config", missionId);
		return RET_MISSION_NOT_EXIST;
	}
	int32_t ret = CanAccept(pPlayer, missionId, reacceptFlag);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//
	MissionTrack* pMissionTrack = AllocMissionTrack();
	if (nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR("[logic] OnAccept MissionID=%u, Allcol MissionTrackObj is nullptr", missionId);
		return RET_FAIL;
	}
	//填充完成条件信息 多任务条件
	std::vector<ItemInfo> conds;
	conds.clear();
	if (RET_SUCCESS != OnExtractCond(pPlayer, pMissionInfo, conds))
	{
		FreeMissionTrack(pMissionTrack);
		MMOLOG_FMT_ERROR("[logic] OnAccept MissionID=%u, OnExtractCond failed...", missionId);
		return RET_FAIL;
	}
	//扣除中间道具
	RemoveReward(pPlayer, pMissionInfo->receRemove);
	//接取任务获取中间道具
	AddReward(pPlayer, pMissionInfo->kind, pMissionInfo->receAdd);
	//填充任务数据信息
	pMissionTrack->missionId = missionId;
	pMissionTrack->dynamicId = missionId; //主支线任务动态任务ID和配置ID一样
	pMissionTrack->acceptMissionTime = Time::Now().sec();
	pMissionTrack->status = MISSION_E_ACCEPTED;
	pMissionTrack->items = conds;
	//添加到可接列表中来
	pMissionPart->_playerTrackMissionMap[pMissionTrack->dynamicId] = pMissionTrack;

	//CTODO增加任务流水记录
	pPlayer->MissionAccpectLog(missionId, pMissionInfo->name, pMissionInfo->kind);

	//接收任务后处理逻辑

	//绑定任务失败后事件 (任务失败是根据完成条件来的,直接通过规则来订阅失败事件)

	//任务接取触发效果
	for (uint32_t i = 0; i < pMissionInfo->triggerEffectIds.size(); i++)
	{
		if (pMissionInfo->triggerEffectIds[i] > 0)
		{
			g_GetEffectMgr()->OnEffect(pPlayer, pMissionInfo->triggerEffectIds[i]);
		}
	}

	//判断任务是否完成
	bool isCompletedFlag = true;
	for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
	{
		if (!pMissionTrack->items[i].completedFlag)
		{
			isCompletedFlag = false;
			break;
		}
	}
	//如果已经完成
	if (isCompletedFlag)
	{
		//如果可以完成
		pMissionTrack->status = MISSION_E_COMPLETION;
	}
	else //没有完成的条件才会注册事件
	{
		//添加任务掉落处理
		OnAddMissionDrop(pPlayer->GetCid(), pMissionPart, pMissionTrack, pMissionInfo->progressLev);
		//注册事件
		for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
		{
			if (!pMissionTrack->items[i].completedFlag)
			{
				int32_t relEvent = MISSION_COND_TYPE_TO_EVENT(pMissionTrack->items[i].type);
				pMissionPart->RegisterEvent(relEvent, pMissionTrack->dynamicId, pMissionInfo->progressLev);
			}
		}
	}

	//如果要通知客户端
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(missionId);
	}

	return RET_SUCCESS;
}

//接取动态任务
int32_t MissionManager::OnAcceptDy(Player* pPlayer, uint32_t missionId, bool notify)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy nullptr == pPlayer", missionId);
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy nullptr == pMissionPart", missionId);
		return RET_FAIL;
	}
	//判断当前的已接任务个数是否已经达到上限了
	/*if (pMissionPart->GetHaveAcceptNumber() >= MISSION_MAX_ACCEPT_NUM)
	{
		return RET_MISSION_HAVE_ACCEPT_NUMBER_LIMIT;
	}*/
	int32_t ret = CanAcceptDy(pPlayer, missionId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//接取任务
	const DyMissionInfo* pMissionInfo = GetDyMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy Have Not MissionID=%u Config, Please Check Mission Config", missionId);
		return RET_MISSION_NOT_EXIST;
	}
	//生成动态任务ID
	uint32_t dymissionId = pMissionPart->AllocNewDyMisssionId();
	if (!pMissionPart->ValidDyMissionId(dymissionId))
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy AllocNewDyMisssionId failed... MissionID=%u ", missionId);
		return RET_FAIL;
	}
	//
	MissionTrack* pMissionTrack = AllocMissionTrack();
	if (nullptr == pMissionTrack)
	{
		pMissionPart->FreeDyMissionId(dymissionId);
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy MissionID=%u, Allcol MissionTrackObj is nullptr", missionId);
		return RET_FAIL;
	}
	//填充完成条件信息 多任务条件
	std::vector<ItemInfo> conds;
	conds.clear();
	uint32_t textId = 0;
	if (RET_SUCCESS != OnExtractDyCond(pPlayer, pMissionInfo, conds, textId))
	{
		pMissionPart->FreeDyMissionId(dymissionId);
		FreeMissionTrack(pMissionTrack);
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy MissionID=%u, OnExtractCond failed...", missionId);
		return RET_FAIL;
	}
	

	//填充任务数据信息
	pMissionTrack->missionId = missionId;
	pMissionTrack->dynamicId = dymissionId;
	pMissionTrack->acceptMissionTime = Time::Now().sec();
	pMissionTrack->status = MISSION_E_ACCEPTED;
	pMissionTrack->items = conds;
	pMissionTrack->textId = textId;
	//提取属性奖励
	OnExtractDyAttrReward(pPlayer, pMissionTrack);
	//添加到可接列表中来
	pMissionPart->_playerTrackMissionMap[pMissionTrack->dynamicId] = pMissionTrack;
	//如果是赏金任务，需要增加接取次数
	if (MISSION_TYPE_ID_BOUNTY == pMissionInfo->kind)
	{
		pMissionPart->_bountyAccetpNum++;
	}

	string mName(pMissionInfo->name);
	//CTODO增加任务流水记录
	pPlayer->MissionAccpectLog(missionId, mName, pMissionInfo->kind);

	//接收任务后处理逻辑

	//绑定任务失败后事件 (任务失败是根据完成条件来的,直接通过规则来订阅失败事件)

	//判断任务是否完成
	bool isCompletedFlag = true;
	for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
	{
		if (!pMissionTrack->items[i].completedFlag)
		{
			isCompletedFlag = false;
			break;
		}
	}
	//如果已经完成
	if (isCompletedFlag)
	{
		//如果可以完成
		pMissionTrack->status = MISSION_E_COMPLETION;
	}
	else //没有完成的条件才会注册事件
	{
		//添加任务掉落处理
		OnAddMissionDrop(pPlayer->GetCid(),pMissionPart, pMissionTrack,1);
		//注册事件
		for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
		{
			if (!pMissionTrack->items[i].completedFlag)
			{
				int32_t relEvent = MISSION_COND_TYPE_TO_EVENT(pMissionTrack->items[i].type);
				pMissionPart->RegisterEvent(relEvent, pMissionTrack->dynamicId, 1);
			}
		}
	}

	//如果要通知客户端
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(dymissionId);
	}
	//接取活动收集任务
	if (MISSION_TYPE_ID_ACT_COLLECT == pMissionInfo->kind)
	{
		g_GetGActivityMgr()->OnAcceptActCollectMission(pPlayer->GetCid());
	}

	return RET_SUCCESS;
}

int32_t MissionManager::OnAcceptDy(Player* pPlayer, MissionTrack *pMissionTrack, bool notify)
{
	if (nullptr == pPlayer || nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy nullptr == pPlayer || nullptr == pMissionTrack");
		return RET_FAIL;
	}
	CharIDType cid = pPlayer->GetCid();
	uint32_t missionId = pMissionTrack->missionId;
	uint32_t dymissionId = pMissionTrack->dynamicId;
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy nullptr == pMissionPart,cid:%lu, missionId:%u,dymissionId:%u ", cid, missionId, dymissionId);
		return RET_FAIL;
	}
	int32_t ret = CanAcceptDy(pPlayer, pMissionTrack);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//接取任务
	const DyMissionInfo* pMissionInfo = GetDyMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy Have Not MissionID Config...cid:%lu, missionid:%u, dymissionid:%u ",cid,missionId,dymissionId);
		return RET_MISSION_NOT_EXIST;
	}
	//校验一次动态任务ID是否已经使用了
	if (pMissionPart->HaveAccpet(pMissionTrack->dynamicId))
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy mission dynamic id error...cid:%lu, missionid:%u, dymissionid:%u ", cid, missionId, dymissionId);
		return RET_FAIL;
	}
	MissionTrack* pNewMissionTrack = AllocMissionTrack();
	if (nullptr == pNewMissionTrack)
	{
		MMOLOG_FMT_ERROR("[logic] OnAcceptDy Allcol MissionTrackObj is nullptr...cid:%lu, missionid:%u,dymissionid:%u ", cid,missionId,dymissionId);
		return RET_FAIL;
	}
	//填充任务数据信息
	pNewMissionTrack->missionId = pMissionTrack->missionId;
	pNewMissionTrack->dynamicId = pMissionTrack->dynamicId;
	pNewMissionTrack->acceptMissionTime = Time::Now().sec();
	pNewMissionTrack->status = MISSION_E_ACCEPTED;
	pNewMissionTrack->items = pMissionTrack->items;
	pNewMissionTrack->textId = pMissionTrack->textId;
	pNewMissionTrack->ration = pMissionTrack->ration;
	pNewMissionTrack->quality = pMissionTrack->quality;
	//提取属性奖励
	OnExtractDyAttrReward(pPlayer, pNewMissionTrack);
	//条件需要预更新
	vector<ItemInfo>::iterator iterCond = pNewMissionTrack->items.begin();
	for (; iterCond != pNewMissionTrack->items.end(); ++iterCond)
	{
		ItemInfo &cond = (*iterCond);
		OnPreUpdateProgress(pPlayer, cond);
	}
	//添加到可接列表中来
	pMissionPart->_playerTrackMissionMap[pNewMissionTrack->dynamicId] = pNewMissionTrack;
	//如果是赏金任务，需要增加接取次数
	if (MISSION_TYPE_ID_BOUNTY == pMissionInfo->kind)
	{
		pMissionPart->_bountyAccetpNum++;
	}
	//判断任务是否完成
	bool isCompletedFlag = true;
	for (uint32_t i = 0; i < pNewMissionTrack->items.size(); i++)
	{
		if (!pNewMissionTrack->items[i].completedFlag)
		{
			isCompletedFlag = false;
			break;
		}
	}
	string mName(pMissionInfo->name);
	pPlayer->MissionAccpectLog(missionId, mName, pMissionInfo->kind);

	//如果已经完成
	if (isCompletedFlag)
	{
		//如果可以完成
		pNewMissionTrack->status = MISSION_E_COMPLETION;
	}
	else //没有完成的条件才会注册事件
	{
		//添加任务掉落处理
		OnAddMissionDrop(pPlayer->GetCid(),pMissionPart, pNewMissionTrack,1);
		//注册事件
		for (uint32_t i = 0; i < pNewMissionTrack->items.size(); i++)
		{
			if (!pNewMissionTrack->items[i].completedFlag)
			{
				int32_t relEvent = MISSION_COND_TYPE_TO_EVENT(pNewMissionTrack->items[i].type);
				pMissionPart->RegisterEvent(relEvent, pNewMissionTrack->dynamicId, 1);
			}
		}
	}

	//设置传进来的任务接取时间和状态，状态应该和当前已接任务列表中的任务一样
	pMissionTrack->acceptMissionTime = Time::Now().sec();
	pMissionTrack->status = pNewMissionTrack->status;

	//如果要通知客户端
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(dymissionId);
	}

	if (MISSION_TYPE_ID_BOUNTY == pMissionInfo->kind)
	{
		//增加赏金任务已完成次数
		uint64_t lastFresh = pMissionPart->GetMissionFreshTime(pMissionInfo->kind);
		int32_t finishNum = pMissionPart->HaveFinishNumByType(pMissionInfo->kind);
		finishNum += 1;
		pMissionPart->SetDyMissionTrack(pMissionInfo->kind, finishNum, lastFresh);
	}

	return RET_SUCCESS;
}
//提取条件
int32_t MissionManager::OnExtractCond(Player* pPlayer, uint32_t missionId, std::vector<ItemInfo> &conds)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractCond nullptr == pPlayer, missionid:%u ", missionId);
		return RET_FAIL;
	}
	MissionInfo *pMissionInfo = GetMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractCond nullptr == pMissionInfo missionid:%u ", missionId);
		return RET_FAIL;
	}
	return OnExtractCond(pPlayer, pMissionInfo, conds);
}

int32_t MissionManager::OnExtractCond(Player* pPlayer, MissionInfo *pMissionInfo, std::vector<ItemInfo> &conds)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractCond nullptr == pPlayer");
		return RET_FAIL;
	}
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractCond nullptr == pMissionInfo");
		return RET_FAIL;
	}
	MissionPart *pMissionPart = dynamic_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractCond nullptr == pMissionPart missionid:%u ", pMissionInfo->missionId);
		return RET_FAIL;
	}
	const InterExecute &execute = pMissionInfo->execute;
	std::vector<InterItemPair>::const_iterator iter = execute.items.begin();
	for (; iter != execute.items.end(); ++iter)
	{
		const InterItemPair &inter = (*iter);
		//组合条件
		ItemInfo condItem(inter.itemId, 0, inter.itemCount, false, inter.itemType, inter.parma1, inter.parma2, inter.parma3);
		//条件预更新
		OnPreUpdateProgress(pPlayer, condItem);
		//添加到条件列表中
		conds.push_back(condItem);
	}

	return RET_SUCCESS;
}

//提取动态任务条件
int32_t MissionManager::OnExtractDyCond(Player* pPlayer, uint32_t missionId, std::vector<ItemInfo> &conds, uint32_t &textId, bool preUpdate/* = true*/)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pPlayer, missionid:%u ", missionId);
		return RET_FAIL;
	}
	const DyMissionInfo *pDyMissionInfo = GetDyMissionCfgInfo(missionId);
	if (nullptr == pDyMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pDyMissionInfo missionid:%u ", missionId);
		return RET_FAIL;
	}
	return OnExtractDyCond(pPlayer, pDyMissionInfo, conds, textId, preUpdate);
}

int32_t MissionManager::OnExtractDyCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, std::vector<ItemInfo> &conds, uint32_t &textId, bool preUpdate/* = true*/)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pPlayer");
		return RET_FAIL;
	}
	if (nullptr == pDyMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pDyMissionInfo");
		return RET_FAIL;
	}
	MissionPart *pMissionPart = dynamic_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pMissionPart missionid:%u ", pDyMissionInfo->missionId);
		return RET_FAIL;
	}
	//暂时不支持非动态生成，需要非动态生成规则
	if (!pDyMissionInfo->dynamic)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond !pDyMissionInfo->dynamic missionid:%u ", pDyMissionInfo->missionId);
		return RET_FAIL;
	}
	//抽取一个动态条件ID
	if (pDyMissionInfo->setComplete.size() < 1)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond pDyMissionInfo->setComplete.size() < 1  missionid:%u ", pDyMissionInfo->missionId);
		return RET_FAIL;
	}
	VEC_INT32 vecCond;
	vecCond.clear();
	SET_INT32::const_iterator iter = pDyMissionInfo->setComplete.begin();
	for (; iter != pDyMissionInfo->setComplete.end(); ++iter)
	{
		vecCond.push_back((*iter));
	}
	int32_t isize = vecCond.size();
	int32_t rndidx = Random(isize);// 0 - (isize-1)
	int32_t condId = vecCond.at(rndidx);
	const DyConditionInfo *pDyConditionInfo = GetDyConditionCfgInfo(condId);
	if (nullptr == pDyConditionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnExtractDyCond nullptr == pDyConditionInfo missionid:%u,condid:%d ", pDyMissionInfo->missionId,condId);
		return RET_FAIL;
	}
	//动态生成任务条件
	ItemInfo condItem;
	int32_t ret = OnGeneralCond(pPlayer, pDyMissionInfo, pDyConditionInfo, condItem, textId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	if (preUpdate)
	{
		//条件预更新
		OnPreUpdateProgress(pPlayer, condItem);
	}	
	//添加到条件列表中
	conds.push_back(condItem);

	return RET_SUCCESS;
}

//条件预判断(有些条件接取任务时就已经完成了)
void MissionManager::OnPreUpdateProgress(Player *pPlayer, ItemInfo &cond)
{
	if (nullptr == pPlayer || cond.completedFlag)
	{
		return;
	}
	int32_t count = 0;
	int32_t event = MISSION_COND_TYPE_TO_EVENT(cond.type);
	if (M_EVENT_COLL_COLLECT_ITEM == event) //收集物品
	{
		//收集物品		格式：3 = 物品id = 所需物品数目 = 怪物id = 掉落包id = 区域id
		Part *pPackage = pPlayer->GetPart(PART_PACKAGE);
		if (nullptr != pPackage)
		{
			int32_t bindNum = 0;
			int32_t unbindNum = 0;
			count = pPackage->GetItemNum(cond.itemId, unbindNum, bindNum);
		}
	}
	else if (M_EVENT_INBUFF == event) //处于某种BUFF
	{
		// 处于某种buff 格式: 6=buff的id=所需获得次数=0=0=0
		BuffPart* pBuffPart = static_cast<BuffPart*>(pPlayer->GetPart(PART_BUFF));
		if (nullptr != pBuffPart && pBuffPart->BuffEffect_HasBuffBag(cond.itemId))
		{
			count = 1;
		}
	}
	else if (M_EVENT_LEVEL == event) //等级达到多少级
	{
		//升到指定等级	格式: 14=所需等级数值=目标值=0=0=0
		//升级到xx级 ,前端显示 0/1,
		if ((uint64_t)pPlayer->GetAttr(C_LEVEL) >= cond.itemId)
		{
			count = cond.itemId;
		}
	}
	else if (M_EVENT_JOIN_CAMP == event)
	{
		//加入阵营				格式 14001=0=1=0=0=0
		if (pPlayer->GetAttr(C_CAMP_ID) > 0)
		{
			count = 1;
		}
	}
	else if (M_EVENT_JOIN_GUILD == event)
	{
		//加入工会				格式 15001=0=1=0=0=0
		if (pPlayer->GetAttr(C_UNION_ID) > 0)
		{
			count = 1;
		}
	}
	else if (M_EVENT_GOD_LEVEL == event) 
	{
		//前端显示 0 / 1,
		//神格升级				格式 10101=神格id=升级的等级=0=0=0
		GodPart *pGodPart = dynamic_cast<GodPart*>(pPlayer->GetPart(PART_GOD));
		if (nullptr != pGodPart)
		{
			count = (int32_t)pGodPart->GetGodLevel(cond.itemId);
			if (count >= cond.finalValue)
			{
				count = cond.finalValue;
			}
		}
	}
	else if (M_EVENT_SKILL_LEVEL == event)
	{
		SkillPart *pSkilPart = dynamic_cast<SkillPart*>(pPlayer->GetPart(PART_SKILL));
		if (nullptr != pSkilPart)
		{
			count = pSkilPart->GetSkillLev(cond.itemId);
			if (count >= cond.finalValue)
			{
				count = cond.finalValue;
			}
		}
	}
	else
	{
		return;
	}
	if (count > 0)
	{
		ExecuteData data(event, cond.itemId, count);
		bool notify = false;
		OnUpdateCondProcess(data, cond, notify);
	}
}

//更新进度
int32_t  MissionManager::OnUpdateProgress(Player *pPlayer, uint32_t missionId, const ExecuteData& data)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (pMissionPart == nullptr)
	{
		return RET_FAIL;
	}
	//先查找已接列表中是否有该任务
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(missionId);
	if (pMissionPart->_playerTrackMissionMap.end() == iter)
	{
		return RET_MISSION_NOT_EXIST;
	}

	if (MISSION_E_ACCEPTED != iter->second->status)
	{
		return RET_MISSION_STATE_NOT_MATCH;
	}

	bool notify = false;
	//任务执行单元开始执行 多完成条件
	uint32_t size = iter->second->items.size();
	for (uint32_t i = 0; i < size; i++)
	{
		OnUpdateCondProcess(data, iter->second->items[i], notify);
	}

	//判断任务是否完成
	bool isCompletedFlag = true;
	for (uint32_t i = 0; i < size; i++)
	{
		if (!iter->second->items[i].completedFlag)
		{
			isCompletedFlag = false;
			break;
		}
	}

	//如果完成了
	if (isCompletedFlag)
	{
		//任务已经完成
		iter->second->status = MISSION_E_COMPLETION;
		//完成任务
		pMissionPart->OnFinishDy(iter->second->dynamicId);
	}
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(missionId);
	}

	return RET_SUCCESS;
}

//更新条件进度
void MissionManager::OnUpdateCondProcess(const ExecuteData& data, ItemInfo &cond, bool &notify)
{
	int32_t relevent = MISSION_COND_TYPE_TO_EVENT(cond.type);
	if ((uint32_t)relevent != data.type || cond.itemId != data.id || cond.completedFlag)
	{
		return;
	}
	if (M_EVENT_LEVEL == relevent)
	{
		//升级到xx级 ,前端显示 0/1,
		if (data.id >= cond.itemId)
		{
			cond.currentValue = cond.finalValue;
			cond.completedFlag = true;
			notify = true;
		}
	}
	else
	{
		//提交物品的条件，物品扣除来源必须是从任务这边扣除的
		if (MISSION_FINISH_TYPE_SUBMIT_ITEM == cond.type || MISSION_FINISH_TYPE_SUBMIT_EQUIP == cond.type)
		{
			if (S_Mission_SubmitItem != data.source)
			{
				return;
			}
		}
		int32_t currentValue = cond.currentValue + data.count;
		if (currentValue >= 0)
		{
			notify = true;
			if (currentValue >= cond.finalValue)
			{
				cond.currentValue = cond.finalValue;
				cond.completedFlag = true;
			}
			else
			{
				cond.currentValue = currentValue;
				cond.completedFlag = false;
			}
		}
	}
}


//提交任务
int32_t MissionManager::OnSubmit(Player* pPlayer, uint32_t missionId,uint32_t selidx)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmit missionId=%u but pPlayer is nullptr", missionId);
		return RET_FAIL;
	}

	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmit missionId=%u but pMissionPart is nullptr, charId=%lu", missionId, pPlayer->GetId());
		return RET_FAIL;
	}

	Part* pIpackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr == pIpackage)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmit missionId=%u but pIpackage is nullptr, charId=%lu", missionId, pPlayer->GetId());
		return RET_FAIL;
	}

	MissionInfo* pMissionInfo = GetMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmit Have Not MissionID=%u Config, Please Check Mission Config", missionId);
		return RET_MISSION_NOT_EXIST;
	}

	//查找提交的任务是否在已接列表中存在
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(missionId);
	if (pMissionPart->_playerTrackMissionMap.end() == iter)
	{
		return RET_MISSION_NOT_EXIST;
	}
	MissionTrack *pSubmitMissionTrack = iter->second;
	if (nullptr == pSubmitMissionTrack)
	{
		return RET_FAIL;
	}
	uint32_t doneSec = Time::Now().sec() - (uint64_t)pSubmitMissionTrack->acceptMissionTime;
	//判断任务是否完成
	if (MISSION_E_COMPLETION != pSubmitMissionTrack->status)
	{
		return RET_MISSION_STATE_NOT_MATCH;
	}
	bool notify = false;//通知新接取的任务进度
	bool removeFlag = false;//任务已经从已接列表移除的标志
	if (MISSION_TYPE_ID_BANISH != pMissionInfo->kind && pMissionInfo->backTaskId > 0)
	{
		const MissionInfo *pBackMissionInfo = GetMissionCfgInfo(pMissionInfo->backTaskId);
		if (nullptr == pBackMissionInfo)
		{
			LogErrFmtPrint("MissionManager::OnSubmit...can not find backtask cfg...cid:%lu,missionid:%u,backmission:%u ", pPlayer->GetCid(), pMissionInfo->missionId, pMissionInfo->backTaskId);
			return RET_MISSION_CAN_NOT_SUBMIT;
		}
		bool lastMissionFlag = false;
		if (pMissionInfo->chapterId != pBackMissionInfo->chapterId)
		{
			//当前任务和后置任务不再同一个章节，当前任务为当前章节最后一个任务
			lastMissionFlag = true;
		}
		//如果有后续任务，需要先接取后续任务，成功之后才能移除当前任务
		//先移除下当前任务
		pMissionPart->_playerTrackMissionMap.erase(iter);
		//这里需要判断下后置任务所在的章节是否是已经提交过的，如果是已经提交过的，则不需要再接取了
		//支线会出现提交章节最后一个任务的时候，后置任务所在章节是已经提交过的
		//如果章节接取条件配置了前置章节就不会有问题，这里做一下兼容,每次提交任务接取后置任务的时候判断下后置任务所在章节是否已经提交过
		//主线应不会出现这个问题

		//
		if (pMissionPart->HaveChapterSubmit(pBackMissionInfo->chapterId))
		{
			LogInfoFmtPrint("MissionManager::OnSubmit...accept back mission,but back mission chapter have submit..cid:%lu,missionid:%u,backmission:%u,backchapter:%u ", pPlayer->GetCid(), missionId, pMissionInfo->backTaskId, pBackMissionInfo->chapterId);
		}

		//主线任务会自动接取后置任务，其他任务如果是章节最后一个任务则不会自动接取下一个章节的任务
		if (MISSION_TYPE_ID_TRUNK == pMissionInfo->kind || !lastMissionFlag)
		{
			//如果是主线章节最后一个任务，需要先把当前章节加入到已完成章节列表
			bool reacceptFlag = true;
			if (lastMissionFlag)
			{
				pMissionPart->_setSubmitChapter.insert(pMissionInfo->chapterId);
				reacceptFlag = false;
			}

			int32_t retaccept = OnAccept(pPlayer, pMissionInfo->backTaskId, reacceptFlag);
			if (RET_SUCCESS != retaccept)
			{
				//接取后置任务失败，还原删除的任务
				pMissionPart->_playerTrackMissionMap[pSubmitMissionTrack->dynamicId] = pSubmitMissionTrack;
				//失败，如果是支线章节最后一个任务，需要先把当前章节从已完成章节列表移除
				if (lastMissionFlag)
				{
					pMissionPart->_setSubmitChapter.erase(pMissionInfo->chapterId);
				}
				//
				LogErrFmtPrint("MissionManager::OnSubmit...can not accept backtask...cid:%lu,missionid:%u,backmission:%u,retaccept:%d ", pPlayer->GetCid(), pMissionInfo->missionId, pMissionInfo->backTaskId, retaccept);
				//不能提交
				return RET_MISSION_CAN_NOT_SUBMIT;
			}
			notify = true;
		}
		removeFlag = true;
	}

	//移除任务
	int32_t ret = RemoveMission(pPlayer, pSubmitMissionTrack, pMissionInfo);
	if (RET_SUCCESS != ret)
	{
		if (removeFlag)
		{
			LogErrFmtPrint("MissionManager::OnSubmit...RemoveMission failed..cid:%lu,dynamic:%u,missionid:%u,chapter:%u,backmission:%u,ret:%d ", pPlayer->GetCid(), pSubmitMissionTrack->dynamicId, pMissionInfo->missionId, pMissionInfo->chapterId, pMissionInfo->backTaskId, ret);
			//移除失败，正常不会到这里，这个时候已经接取了后置任务，这里直接回收此次提交的任务
			//已经从已接列表移除，这里直接回收任务对象
			FreeMissionTrack(pSubmitMissionTrack);
		}
		else
		{
			return ret;
		}		
	}

	pPlayer->MissionCompleteLog(missionId, pMissionInfo->name, pMissionInfo->kind, doneSec);
	
	//完成任务触发事件
	uint32_t missionType = pMissionInfo->kind;
	FinishTaskEvent taskEvent;
	taskEvent.taskId = missionId;
	taskEvent.taskType = missionType;
	taskEvent.cid = pPlayer->GetCid();
	g_GetEvent()->FireExecute(EVENT_FINISH_TASK, pPlayer->GetCid(), pPlayer->CreatureKind(), &taskEvent, sizeof(FinishTaskEvent));

	//固定奖励放后面，可能给予奖励之后会触发刷新可接列表
	g_GetMissionManager()->AddReward(pPlayer, pMissionInfo->kind, pMissionInfo->subAward);

	//可选奖励
	Part *pPackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr != pPackage)
	{
		if (pMissionInfo->subAwardRand.size() > 0 )
		{
			if (selidx >= 0 && selidx < pMissionInfo->subAwardRand.size())
			{
				TASK_REWARD reward;
				reward.push_back(pMissionInfo->subAwardRand[selidx]);
				g_GetMissionManager()->AddReward(pPlayer, pMissionInfo->kind, reward);
			}
			else
			{
				MMOLOG_FMT_ERROR("[logic] OnSubmit  cid:%lu, missionId = %u but index is error index = %u...", pPlayer->GetCid(), missionId, selidx);
			}
		}
	}

	if (MISSION_TYPE_ID_BANISH != pMissionInfo->kind)
	{
		//提交任务
		pMissionPart->OnSubmit(missionId, pMissionInfo->backTaskId, pMissionInfo->chapterId, pMissionInfo->kind);
	}


	//如果要通知客户端
	if (notify)
	{
		pMissionPart->UpdateMissionProgress(pMissionInfo->backTaskId);
	}

	return RET_SUCCESS;
}

//提交动态任务
int32_t MissionManager::OnSubmitDy(Player* pPlayer, uint32_t dymissionId)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmitDy dymissionId=%u but pPlayer is nullptr", dymissionId);
		return RET_FAIL;
	}

	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmitDy dymissionId=%u but pMissionPart is nullptr, charId=%lu", dymissionId, pPlayer->GetId());
		return RET_FAIL;
	}

	Part* pIpackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr == pIpackage)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmitDy dymissionId=%u but pIpackage is nullptr, charId=%lu", dymissionId, pPlayer->GetId());
		return RET_FAIL;
	}
	//查找提交的任务是否在已接列表中存在
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(dymissionId);
	if (pMissionPart->_playerTrackMissionMap.end() == iter)
	{
		return RET_MISSION_NOT_EXIST;
	}
	//判断任务是否完成
	if (MISSION_E_COMPLETION != iter->second->status)
	{
		return RET_MISSION_STATE_NOT_MATCH;
	}
	uint32_t missionId = iter->second->missionId;
	int32_t quality = iter->second->quality;
	int32_t rate = (int32_t)iter->second->ration;
	uint64_t acceptTime = (uint64_t)iter->second->acceptMissionTime;
	MAP_INT32_INT32 mapAttrReward = iter->second->mapAttrReward;
	const DyMissionInfo* pMissionInfo = GetDyMissionCfgInfo(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnSubmitDy Have Not missionId=%u,dymissionid:%u  Config, Please Check Mission Config , charId=%lu ", missionId, dymissionId,pPlayer->GetCid());
		return RET_MISSION_NOT_EXIST;
	}
	//移除任务
	int32_t ret = RemoveDyMission(pPlayer,dymissionId,true);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//赏金任务再接取的时候记录次数，其他的都是完成的时候记录次数
	int32_t finishNum = pMissionPart->HaveFinishNumByType(pMissionInfo->kind);
	if (MISSION_TYPE_ID_BOUNTY != pMissionInfo->kind)
	{
		//增加动态任务已完成次数
		uint64_t lastFresh = pMissionPart->GetMissionFreshTime(pMissionInfo->kind);
		finishNum += 1;
		pMissionPart->SetDyMissionTrack(pMissionInfo->kind, finishNum, lastFresh);
	}	

	//任务提交处理
	pMissionPart->OnSubmitDy(dymissionId,pMissionInfo->kind, quality);

	//完成任务流水日志
	uint32_t doneSec = Time::Now().sec() - acceptTime;
	string mName(pMissionInfo->name);
	pPlayer->MissionCompleteLog(missionId, mName, pMissionInfo->kind, doneSec);

	//任务奖励
	OnAddDyMissionReward(pPlayer, pMissionInfo->kind, mapAttrReward, finishNum, rate);

	//完成任务触发事件
	uint32_t missionType = pMissionInfo->kind;
	FinishTaskEvent taskEvent;
	taskEvent.taskId = missionId;
	taskEvent.taskType = missionType;
	taskEvent.cid = pPlayer->GetCid();
	g_GetEvent()->FireExecute(EVENT_FINISH_TASK, pPlayer->GetCid(), pPlayer->CreatureKind(), &taskEvent, sizeof(FinishTaskEvent));

	return RET_SUCCESS;
}

//放弃任务
int32_t MissionManager::OnAbandon(Player* pPlayer, uint32_t missionId)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandon missionId=%u but pPlayer is nullptr", missionId);
		return RET_FAIL;
	}

	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandon missionId=%u but pMissionPart is nullptr, charId=%lu", missionId, pPlayer->GetId());
		return RET_FAIL;
	}
	MissionInfo* pMissionInfo = g_GetMissionManager()->FindMissionInfoById(missionId);
	if (nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandon missionId=%u can not find mission config charId=%lu", missionId, pPlayer->GetId());
		return RET_FAIL;
	}
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(missionId);
	if (iter == pMissionPart->_playerTrackMissionMap.end())
	{
		return RET_MISSION_NOT_EXIST;
	}
	MissionTrack *pAbandonTrack = iter->second;
	if (nullptr == pAbandonTrack)
	{
		return RET_MISSION_NOT_EXIST;
	}
	LogDebugFmtPrint("MissionManager::OnAbandon....cid:%lu,dynamicid:%u, missionid:%u,status:%u ",pPlayer->GetCid(), pAbandonTrack->dynamicId, pAbandonTrack->missionId,pAbandonTrack->status);
	//主线只能放弃任务状态失败的任务
	if (MISSION_TYPE_ID_TRUNK == pMissionInfo->kind)
	{
		if (MISSION_E_FAILURE != pAbandonTrack->status)
		{
			return RET_MISSION_NOT_ABANDON;
		}		
		//需要先移除任务，然后再接取
		int32_t retremove = RemoveMission(pPlayer, pAbandonTrack, pMissionInfo);
		if (RET_SUCCESS != retremove)
		{
			LogErrFmtPrint("MissionManager::OnAbandon...remove trunk misssion failed...cid:%lu,missionid:%u,retremove:%d", pPlayer->GetCid(), missionId, retremove);
			return RET_FAIL;
		}
		//重新接取任务
		int32_t retaccept = OnAccept(pPlayer,missionId,true,true);
		if (RET_SUCCESS != retaccept)
		{
			MMOLOG_FMT_ERROR("MissionManager::OnAbandon...OnAccept trunk misssion failed...cid:%lu,missionid:%u,retaccept:%d", pPlayer->GetCid(), missionId, retaccept);
			return RET_FAIL;
		}

		return RET_SUCCESS;
	}
	//
	if (MISSION_E_FAILURE == pAbandonTrack->status)
	{
		//失败状态
		if (M_ABANDON_TYPE_REMOVE_CHAPTER == pMissionInfo->failexec)
		{
			//移除整个目录
		}
		else if (M_ABANDON_TYPE_REMOVE_CURRENT == pMissionInfo->failexec)
		{
			//移除当前任务
			int32_t retremove = RemoveMission(pPlayer, pAbandonTrack, pMissionInfo);
			if (RET_SUCCESS != retremove)
			{
				LogErrFmtPrint("MissionManager::OnAbandon00...remove misssion failed...cid:%lu,missionid:%u,retremove:%d,failexec:%d", pPlayer->GetCid(), missionId, retremove, pMissionInfo->failexec);
				return RET_FAIL;
			}
			return RET_SUCCESS;
		}
		else if (M_ABANDON_TYPE_ACCEPT_CURRENT == pMissionInfo->failexec)
		{
			//移除任务
			int32_t retremove = RemoveMission(pPlayer, pAbandonTrack, pMissionInfo);
			if (RET_SUCCESS != retremove)
			{
				LogErrFmtPrint("MissionManager::OnAbandon00...remove misssion failed...cid:%lu,missionid:%u,retremove:%d,failexec:%d", pPlayer->GetCid(), missionId, retremove,pMissionInfo->failexec);
				return RET_FAIL;
			}
			//重新接取任务
			int32_t retaccept = OnAccept(pPlayer, missionId, true, true);
			if (RET_SUCCESS != retaccept)
			{
				MMOLOG_FMT_ERROR("MissionManager::OnAbandon11...OnAccept misssion failed...cid:%lu,missionid:%u,retaccept:%d,failexec:%d ", pPlayer->GetCid(), missionId, retaccept, pMissionInfo->failexec);
				return RET_FAIL;
			}
			return RET_SUCCESS;
		}
		else
		{
			MMOLOG_FMT_ERROR("MissionManager::OnAbandon22...unkown pMissionInfo->failexec...cid:%lu,missionid:%u,failexec:%d ", pPlayer->GetCid(), missionId, pMissionInfo->failexec);
			return RET_FAIL;
		}
	}

	MissionPart::PlayerTrackMissionMap mapAbandon;
	mapAbandon.clear();
	MissionPart::PlayerTrackMissionMap::iterator iterA = pMissionPart->_playerTrackMissionMap.begin();
	for (; iterA != pMissionPart->_playerTrackMissionMap.end(); ++iterA)
	{
		MissionTrack *pMissionTrack = iterA->second;
		if (nullptr == pMissionTrack)
		{
			continue;
		}
		//记录同一章节的任务
		uint32_t missionId = pMissionTrack->missionId;
		MissionInfo *pAbandonMissionInfo = GetMissionCfgInfo(missionId);
		if (nullptr != pAbandonMissionInfo && pAbandonMissionInfo->chapterId == pMissionInfo->chapterId)
		{
			mapAbandon[pMissionTrack->dynamicId] = pMissionTrack;
		}
	}
	if (mapAbandon.size() <= 0)
	{
		return RET_MISSION_NOT_EXIST;
	}

	MissionPart::PlayerTrackMissionMap::iterator iterAbandon = mapAbandon.begin();
	for (; iterAbandon != mapAbandon.end(); ++iterAbandon)
	{
		MissionTrack *pMissionTrack = iter->second;
		if (nullptr == pMissionTrack)
		{
			continue;
		}
		MissionInfo *pAbandonMissionInfo = GetMissionCfgInfo(pMissionTrack->missionId);
		if (nullptr == pAbandonMissionInfo)
		{
			continue;
		}
		int32_t ret = RemoveMission(pPlayer, pMissionTrack, pAbandonMissionInfo);
		if (RET_SUCCESS == ret)
		{
			pPlayer->MissionFailLog(missionId, pAbandonMissionInfo->name, pAbandonMissionInfo->kind, "放弃任务");
		}
	}
	//放弃章节
	pMissionPart->OnAbandon(pMissionInfo->chapterId);
	

	return RET_SUCCESS;
}

//放弃动态任务
int32_t MissionManager::OnAbandonDy(Player* pPlayer, uint32_t dymissionId, bool notify)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandonDy dymissionId=%u but pPlayer is nullptr", dymissionId);
		return RET_FAIL;
	}

	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandonDy dymissionId=%u but pMissionPart is nullptr, charId=%lu", dymissionId, pPlayer->GetId());
		return RET_FAIL;
	}

	Part* pIpackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr == pIpackage)
	{
		MMOLOG_FMT_ERROR("[logic] OnAbandonDy dymissionId=%u but pIpackage is nullptr, charId=%lu", dymissionId, pPlayer->GetId());
		return RET_FAIL;
	}
	int32_t ret = RET_MISSION_NOT_EXIST;
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(dymissionId);
	if (iter != pMissionPart->_playerTrackMissionMap.end() && MISSION_E_SUBMITTED > iter->second->status)
	{
		uint32_t missionId = iter->second->missionId;
		const DyMissionInfo *pDyMissionCfgInfo = GetDyMissionCfgInfo(missionId);
		if (nullptr == pDyMissionCfgInfo)
		{
			MMOLOG_FMT_ERROR("[logic] OnAbandonDy Have Not MissionID=%u, dymissionid:%u, Config, Please Check Mission Config", missionId,dymissionId);
			return RET_MISSION_NOT_EXIST;
		}
		//工会，环，周三活动任务 不能放弃
		if (MISSION_TYPE_ID_LOOP == pDyMissionCfgInfo->kind
			|| MISSION_TYPE_ID_GUILD == pDyMissionCfgInfo->kind
			|| MISSION_TYPE_ID_ACT_COLLECT == pDyMissionCfgInfo->kind
			)
		{
			return RET_MISSION_NOT_ABANDON;
		}
		ret = RemoveDyMission(pPlayer, dymissionId, notify);
		if (RET_SUCCESS == ret)
		{
			pMissionPart->OnAbandonDy(dymissionId, (int32_t)pDyMissionCfgInfo->kind);

			string mName(pDyMissionCfgInfo->name);
			pPlayer->MissionFailLog(missionId, mName, pDyMissionCfgInfo->kind, "放弃任务");
		}		 
	}

	return ret;
}

//移除任务
int32_t MissionManager::RemoveMission(Player* pPlayer, MissionInfo* pMissionInfo)
{
	if (nullptr == pPlayer || nullptr == pMissionInfo)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveMission but pPlayer is nullptr or pMissionInfo is nullptr ...");
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveMission missionId=%u but pMissionPart is nullptr, charId=%lu", pMissionInfo->missionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(pMissionInfo->missionId);
	if (iter == pMissionPart->_playerTrackMissionMap.end())
	{
		MMOLOG_FMT_ERROR("[logic] RemoveMission missionId=%u can not find mission data , charId=%lu", pMissionInfo->missionId, pPlayer->GetCid());
		return RET_FAIL;
	}

	return RemoveMission(pPlayer, iter->second, pMissionInfo);
}

//移除任务
int32_t MissionManager::RemoveMission(Player *pPlayer, MissionTrack *pMissinTrack, MissionInfo* pMissionInfo)
{
	if (nullptr == pPlayer || nullptr == pMissinTrack || nullptr == pMissionInfo)
	{
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveMission 11 missionId=%u but pMissionPart is nullptr, charId=%lu", pMissinTrack->missionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	//移除任务掉落
	OnDelMissionDrop(pPlayer, pMissinTrack);
	//移除任务数据
	pMissionPart->_playerTrackMissionMap.erase(pMissinTrack->dynamicId);
	//回收任务数据
	FreeMissionTrack(pMissinTrack);
	//移除任务中间产物
	RemoveReward(pPlayer, pMissionInfo->subRemove);
	//移除接取任务发放的任务物品
	RemoveReward(pPlayer, pMissionInfo->receAddTask);
	//移除效果
	for (uint32_t i = 0; i < pMissionInfo->subEffectId.size(); i++)
	{
		if (pMissionInfo->subEffectId[i] > 0)
		{
			g_GetEffectMgr()->OnEffect(pPlayer, pMissionInfo->subEffectId[i]);
		}
	}
	//移除任务事件监听
	pMissionPart->RemoveEvent(pMissionInfo->missionId);
	//通知删除任务
	pMissionPart->NotifyDelMission(pMissionInfo->missionId);
	//
	return RET_SUCCESS;
}

int32_t MissionManager::RemoveDyMission(Player* pPlayer, uint32_t dymissionId, bool notify)
{
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveDyMission but pPlayer is nullptr or pMissionInfo is nullptr ...dymissionId:%u ", dymissionId);
		return RET_FAIL;
	}
	MissionPart* pMissionPart = static_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveDyMission  dymissionId:%u  but pMissionPart is nullptr, charId=%lu", dymissionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	if (!pMissionPart->ValidDyMissionId(dymissionId))
	{
		MMOLOG_FMT_ERROR("[logic] RemoveDyMission  dymissionId:%u ValidDyMissionId failed, charId=%lu", dymissionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	MissionPart::PlayerTrackMissionMap::iterator iter = pMissionPart->_playerTrackMissionMap.find(dymissionId);
	if (iter == pMissionPart->_playerTrackMissionMap.end())
	{
		MMOLOG_FMT_ERROR("[logic] RemoveDyMission dymissionId:%u can not find mission data , charId=%lu",  dymissionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	uint32_t missionId = iter->second->missionId;
	const DyMissionInfo *pDyMissionCfgInfo = GetDyMissionCfgInfo(missionId);
	if (nullptr == pDyMissionCfgInfo)
	{
		MMOLOG_FMT_ERROR("[logic] RemoveDyMission dymissionId:%u, missionid:%u, can not find mission config , charId=%lu", dymissionId, missionId, pPlayer->GetCid());
		return RET_FAIL;
	}
	//移除任务掉落
	OnDelMissionDrop(pPlayer, iter->second);
	//移除任务物品
	OnDelMissionItem(pPlayer, iter->second);
	//回收任务数据
	FreeMissionTrack(iter->second);
	//移除任务数据
	pMissionPart->_playerTrackMissionMap.erase(iter);
	//回收动态任务ID,如果是阵营任务或者赏金任务，动态ID由阵营和赏金可接列表那里回收	
	if ( MISSION_TYPE_ID_BOUNTY != pDyMissionCfgInfo->kind && MISSION_TYPE_ID_CAMP != pDyMissionCfgInfo->kind)
	{
		pMissionPart->FreeDyMissionId(dymissionId);
	}	
	//移除任务事件监听
	pMissionPart->RemoveEvent(dymissionId);
	//通知删除任务
	if (notify)
	{
		pMissionPart->NotifyDelMission(dymissionId);
	}

	return RET_SUCCESS;
}

//提取动态任务属性奖励
int32_t MissionManager::OnExtractDyAttrReward(Player* pPlayer, MissionTrack *pNewMissinTrack)
{
	if (nullptr == pPlayer || nullptr == pNewMissinTrack)
	{
		return RET_FAIL;
	}
	MissionPart *pMissionPart = dynamic_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		return RET_FAIL;
	}
	const DyMissionInfo *pDyMissionCfgInfo = GetDyMissionCfgInfo(pNewMissinTrack->missionId);
	if (nullptr == pDyMissionCfgInfo)
	{
		return RET_FAIL;
	}
	int32_t level = pPlayer->GetAttr(C_LEVEL);
	if (MISSION_TYPE_ID_BOUNTY == pDyMissionCfgInfo->kind)
	{
		//赏金任务
		GetBountyBaseReward(pNewMissinTrack->mapAttrReward, level, pNewMissinTrack->quality);
	}
	else if (MISSION_TYPE_ID_CAMP == pDyMissionCfgInfo->kind)
	{
		//阵营任务
		GetCampBaseReward(pNewMissinTrack->mapAttrReward, level, pNewMissinTrack->quality);
	}
	else if (MISSION_TYPE_ID_LOOP == pDyMissionCfgInfo->kind)
	{
		//环任务
		int32_t loopNum = pMissionPart->HaveFinishNumByType(MISSION_TYPE_ID_LOOP) + 1;
		//获取基础奖励，特殊奖励只有物品，没有属性奖励
		//取当前等级升级需要的最大经验
		int64_t upgradeExp = 0;
		int32_t level = pPlayer->GetAttr(C_LEVEL);
		const RoleExpCfgInfo *pExpCfg = g_GetRoleExpCfgTable()->GetRoleExpCfgInfo(level);
		if (nullptr != pExpCfg)
		{
			upgradeExp = (int64_t)pExpCfg->exp;
		}
		GetLoopBaseReward(pNewMissinTrack->mapAttrReward, loopNum, level, upgradeExp);
	}
	else if (MISSION_TYPE_ID_GUILD == pDyMissionCfgInfo->kind)
	{
		//工会任务
		int32_t guildLoopNum = pMissionPart->HaveFinishNumByType(MISSION_TYPE_ID_GUILD) + 1;
		//获取基础奖励，特殊奖励只有物品，没有属性奖励
		GetGuildBaseReward(pNewMissinTrack->mapAttrReward, guildLoopNum, level,pPlayer->GetAttr(C_UNION_VAULT_LEVEL));
	}
	else if (MISSION_TYPE_ID_GUILD_DAILY == pDyMissionCfgInfo->kind)
	{
		//工会日常任务
		int32_t guildDailyLoopNum = pMissionPart->HaveFinishNumByType(MISSION_TYPE_ID_GUILD_DAILY) + 1;
		int32_t level = pPlayer->GetAttr(C_LEVEL);
		int32_t officeLev = pPlayer->GetAttr(C_UNION_OFFICE_LEVEL);
		GetGuildDailyBaseReward(pNewMissinTrack->mapAttrReward, level, officeLev,guildDailyLoopNum);
		pNewMissinTrack->ration = (uint32_t)GetGuildDailyRewardMulti(guildDailyLoopNum);
	}
	else if (MISSION_TYPE_ID_DAILY == pDyMissionCfgInfo->kind)
	{
		//日常任务
		int32_t dailyLoopNum = pMissionPart->HaveFinishNumByType(MISSION_TYPE_ID_DAILY) + 1;
		int32_t level = pPlayer->GetAttr(C_LEVEL);
		GetDailyBaseReward(pNewMissinTrack->mapAttrReward, level, dailyLoopNum);
		pNewMissinTrack->ration = (uint32_t)GetDailyRewardMulti(dailyLoopNum);
	}
	else if (MISSION_TYPE_ID_ACT_COLLECT == pDyMissionCfgInfo->kind)
	{
		//活动收集
		int32_t level = pPlayer->GetAttr(C_LEVEL);
		GetActBaseReward(pNewMissinTrack->mapAttrReward, level);
	}
	else if (MISSION_TYPE_ID_DEPUTY_COLLECT == pDyMissionCfgInfo->kind)
	{
		int32_t deputyLoopNum = pMissionPart->HaveFinishNumByType(MISSION_TYPE_ID_DEPUTY_COLLECT) + 1;
		int32_t level = pPlayer->GetAttr(C_LEVEL);
		vector<ItemInfo>::iterator iterCond = pNewMissinTrack->items.begin();
		if (iterCond != pNewMissinTrack->items.end())
		{
			const ItemInfo &cond = (*iterCond);
			GetDeputyBaseReward(pNewMissinTrack->mapAttrReward, level, deputyLoopNum, cond.itemId);
		}
		pNewMissinTrack->ration = (uint32_t)GetDeputyRewardMulti(deputyLoopNum);
	}
	else if (MISSION_TYPE_ID_TREASURE == pDyMissionCfgInfo->kind)
	{
		GetTreasureBaseReward(pNewMissinTrack->mapAttrReward);
	}

	return RET_SUCCESS;
}

//添加任务掉落
int32_t MissionManager::OnAddMissionDrop(CharIDType cid, MissionPart *pMissionPart, MissionTrack *pMissionTrack, int32_t progressLev)
{
	if (nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR(" OnAddMissionDrop... nullptr == pMissionTrack cid:%lu ", cid);
		return RET_FAIL;
	}
	uint32_t missionId = pMissionTrack->missionId;
	uint32_t dymissionId = pMissionTrack->dynamicId;
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR(" OnAddMissionDrop... nullptr == pMissionPart cid:%lu, missionId:%u,dymissionId:%u ", cid, missionId, dymissionId);
		return RET_FAIL;
	}
	std::vector<ItemInfo>::iterator iter = pMissionTrack->items.begin();
	for (; iter != pMissionTrack->items.end(); ++iter)
	{
		ItemInfo &cond = (*iter);
		if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == cond.type
			|| MISSION_FINISH_TYPE_COLLECT_MONS == cond.type
			)
		{
			//打怪收集		格式 302=物品id=物品数量=怪物id=宝箱id=追踪区域id
			//采集怪物		格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
			if (!pMissionPart->AddMissionDrop(dymissionId, cond.parma1, 0, cond.parma2,progressLev))
			{
				MMOLOG_FMT_ERROR("OnAddMissionDrop...pMissionPart->AddMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}
		/*//打怪采集和采集怪物会有掉落或者宝箱
		if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == cond.type)
		{
			//打怪收集		格式 302=物品id=物品数量=怪物id=掉落包id=追踪区域id
			if (!pMissionPart->AddMissionDrop(dymissionId, cond.parma1, cond.parma2, 0))
			{
				MMOLOG_FMT_ERROR("OnAddMissionDrop...pMissionPart->AddMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}
		else if (MISSION_FINISH_TYPE_COLLECT_MONS == cond.type)
		{
			//采集怪物		格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
			if (!pMissionPart->AddMissionDrop(dymissionId, cond.parma1, 0, cond.parma2))
			{
				MMOLOG_FMT_ERROR("OnAddMissionDrop...pMissionPart->AddMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}				*/
	}
	return RET_SUCCESS;
}

//移除任务掉落
int32_t MissionManager::OnDelMissionDrop(Player* pPlayer, MissionTrack *pMissionTrack)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	CharIDType cid = pPlayer->GetCid();
	if (nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR(" OnDelMissionDrop... nullptr == pMissionTrack cid:%lu ", cid);
		return RET_FAIL;
	}
	uint32_t missionId = pMissionTrack->missionId;
	uint32_t dymissionId = pMissionTrack->dynamicId;
	MissionPart *pMissionPart = dynamic_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR(" OnDelMissionDrop... nullptr == pMissionPart cid:%lu, missionId:%u,dymissionId:%u ", cid, missionId, dymissionId);
		return RET_FAIL;
	}
	std::vector<ItemInfo>::iterator iter = pMissionTrack->items.begin();
	for (; iter != pMissionTrack->items.end(); ++iter)
	{
		ItemInfo &cond = (*iter);
		if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == cond.type
			|| MISSION_FINISH_TYPE_COLLECT_MONS == cond.type
			)
		{
			//打怪收集		格式 302=物品id=物品数量=怪物id=宝箱id=追踪区域id
			//采集怪物		格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
			if (!pMissionPart->DelMissionDrop(dymissionId, cond.parma1))
			{
				MMOLOG_FMT_ERROR("OnDelMissionDrop...pMissionPart->DelMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}
/*

		//打怪采集和采集怪物会有掉落或者宝箱
		if (MISSION_FINISH_TYPE_COLLECT_KILL_MONS == cond.type)
		{
			//打怪收集		格式 302=物品id=物品数量=怪物id=掉落包id=追踪区域id
			if (!pMissionPart->DelMissionDrop(dymissionId, cond.parma1))
			{
				MMOLOG_FMT_ERROR("OnDelMissionDrop...pMissionPart->DelMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}
		else if (MISSION_FINISH_TYPE_COLLECT_MONS == cond.type)
		{
			//采集怪物		格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
			if (!pMissionPart->DelMissionDrop(dymissionId, cond.parma1))
			{
				MMOLOG_FMT_ERROR("OnDelMissionDrop...pMissionPart->DelMissionDrop failed....cid:%lu, missionid:%u, dymissionid:%u, condtype:%d,itemid:%u,finalvalue:%u,param1:%d,param2:%d,param3:%d ", cid, missionId, dymissionId, cond.type, cond.itemId, cond.finalValue, cond.parma1, cond.parma2, cond.parma3);
			}
		}*/
	}
	return RET_SUCCESS;
}

//移除任务物品
int32_t MissionManager::OnDelMissionItem(Player* pPlayer, MissionTrack *pMissionTrack)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	CharIDType cid = pPlayer->GetCid();
	if (nullptr == pMissionTrack)
	{
		MMOLOG_FMT_ERROR(" OnDelMissionItem... nullptr == pMissionTrack cid:%lu ", cid);
		return RET_FAIL;
	}
	Part *pPackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr == pPackage)
	{
		MMOLOG_FMT_ERROR(" OnDelMissionItem... nullptr == pPackage cid:%lu ", cid);
		return RET_FAIL;
	}
	std::vector<ItemInfo>::iterator iter = pMissionTrack->items.begin();
	for (; iter != pMissionTrack->items.end(); ++iter)
	{
		ItemInfo &cond = (*iter);
		if (MISSION_FINISH_TYPE_COLLECT_ITEM == cond.type
			|| MISSION_FINISH_TYPE_COLLECT_CLIENT == cond.type
			|| MISSION_FINISH_TYPE_COLLECT_MONS == cond.type
			)
		{
			SItemSourceParam sourceParam;
			sourceParam.source = S_MISSION;
			pPackage->RemoveItem(cond.itemId, cond.finalValue, sourceParam);
		}
	}
	return RET_SUCCESS;
}

//动态任务奖励
int32_t MissionManager::OnAddDyMissionReward(Player *pPlayer, int32_t missionType, MAP_INT32_INT32 &mapAttrReward, int32_t loopCount, int32_t rate)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	//属性奖励
	int32_t unionContri = 0;
	int32_t unionMoney = 0;
	int32_t prestige = 0;
	int32_t killValue = 0;
	MAP_INT32_INT32 mapDeuptyCollect;
	mapDeuptyCollect.clear();

	float frate = 1.0f;
	if (rate > 0)
	{
		frate = (float)rate / (float)MISSION_RATION_BASE;
	}
	MAP_INT32_INT32::iterator iter = mapAttrReward.begin();
	for (; iter != mapAttrReward.end(); ++iter)
	{
		int32_t key = iter->first;
		int32_t value = ceil(iter->second * frate);
		if (C_EXP == key)
		{
			pPlayer->AddExp(value);
		}
		//阵营声望需要特殊处理
		else if (C_CAMP_PRESTIGE == key)
		{
			MAP_UINT64_INT32 mapAttr;
			mapAttr[pPlayer->GetCid()] = value;
			g_GetPlayerMgr()->L2C_AddPrestige(mapAttr);
		}
		//工会贡献
		else if (C_UNION_CONTRI == key)
		{
			unionContri += value;
		}
		else if (C_UNION_MONEY == key)
		{
			unionMoney += value;
		}
		else if (C_CAMP_PRESTIGE == key)
		{
			//阵营声望需要特殊处理
			prestige += value;
		}
		else if (C_COLLECT_HERBS == key)
		{
			mapDeuptyCollect[ECollectDeputyType_Herbs] += value;
		}
		else if (C_COLLECT_MINE == key)
		{
			mapDeuptyCollect[ECollectDeputyType_Mine] += value;
		}
		else if (C_COLLECT_FISH == key)
		{
			mapDeuptyCollect[ECollectDeputyType_Fish] += value;
		}
		else if (C_COLLECT_PEEL == key)
		{
			mapDeuptyCollect[ECollectDeputyType_Peel] += value;
		}
		else if (C_GOLD == key
			|| C_DIAMOND == key
			|| C_DIAMOND_BIND == key  //金钱相关的调用另外的接口
			)
		{
			pPlayer->AddSourceAttr(key, value, true, S_MISSION);
		}
		else if (C_KILLING_VALUE == key)
		{
			killValue += value;
		}
		else
		{
			pPlayer->AddAttr(key, value, true);
		}
	}
	if (unionContri > 0 || unionMoney > 0)
	{
		LC_UnionUpdateAttrReq req;
		req.set_charid(pPlayer->GetCid());
		req.set_unionmoney(unionMoney);
		req.set_unioncontri(unionContri);
		g_GetLogicService()->SendDataToCenter(EMODULE_ID_UNION, LOGIC_TO_CENTER_UNION_UPDATE_ATTR, &req);
	}
	if (prestige > 0)
	{
		MAP_UINT64_INT32 mapAttr;
		mapAttr[pPlayer->GetCid()] = prestige;
		g_GetPlayerMgr()->L2C_AddPrestige(mapAttr);
	}

	//特殊奖励,环和工会任务才会有特殊奖励
	uint32_t itemId = 0;
	int32_t num = 0;
	int8_t bind = (int8_t)EBindState::EBindState_no;
	uint32_t boxId = 0;
	SItemSourceParam soureParam;
	soureParam.source = S_MISSION;
	if (MISSION_TYPE_ID_GUILD == missionType)
	{
		GetGuildSpecialReward(boxId,loopCount);
	}
	else if (MISSION_TYPE_ID_LOOP == missionType)
	{
		soureParam.notifySource = ENotifyType_Item_LoopMission;
		GetLoopSpecialReward(boxId, loopCount);
	}
	else if (MISSION_TYPE_ID_GUILD_DAILY == missionType)
	{
		boxId = GetGuildDailyRandBoxReward(loopCount);
	}
	else if (MISSION_TYPE_ID_ACT_COLLECT == missionType)
	{
		soureParam.notifySource = ENotifyType_Item_NolinTreasure;
		soureParam.notifyVal = g_GetDuplicateCfgMgr()->GetNpcCollectActId();
		boxId = GetActRandBoxReward(loopCount);
	}
	else if (MISSION_TYPE_ID_DAILY == missionType)
	{
		boxId = GetDailyRandBoxReward(loopCount);
	}
	else if (MISSION_TYPE_ID_TREASURE == missionType)
	{
		GetTreasureBaseItemReward(itemId, num, bind);
	}

	if (itemId >0 && num > 0)
	{
		Part *pPackage = pPlayer->GetPart(PART_PACKAGE);
		if (nullptr != pPackage)
		{
			pPackage->AddItem(itemId, num, soureParam, bind);
		}
	}
	if (boxId > 0)
	{
		VEC_INT32 vecBox;
		vecBox.clear();
		vecBox.push_back(boxId);
		g_GetDropMgr()->PlayerAddBox(pPlayer, vecBox, soureParam);
	}
	if (mapDeuptyCollect.size() > 0)
	{
		DeputyPart *pDeputyPart = dynamic_cast<DeputyPart*>(pPlayer->GetPart(PART_DEPUTY));
		if (nullptr != pDeputyPart)
		{
			MAP_INT32_INT32::iterator iterDeuty = mapDeuptyCollect.begin();
			for (; iterDeuty != mapDeuptyCollect.end(); ++iterDeuty)
			{
				pDeputyPart->AddCollectEnergy(iterDeuty->first, iterDeuty->second);
			}
		}
	}	
	if (killValue > 0)
	{
		PvpPart *pPvpPart = dynamic_cast<PvpPart*>(pPlayer->GetPart(PART_PVP));
		if (nullptr != pPvpPart)
		{
			pPvpPart->SubPkKillingValue(killValue);
			pPvpPart->SendPvpKillingValue();
		}
	}

	return RET_SUCCESS;
}

//生成任务条件
int32_t MissionManager::OnGeneralCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, ItemInfo &cond, uint32_t &textId)
{
	if (nullptr == pPlayer || nullptr == pDyConditionInfo || nullptr == pDyMissionInfo)
	{
		return RET_FAIL;
	}
	if (pDyConditionInfo->vecType.size() < 1)
	{
		MMOLOG_FMT_ERROR("[logic] OnGeneralCond pDyConditionInfo->vecType.size() < 1... missionid:%u,condid:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId);
		return RET_FAIL;
	}
	//随机完成条件类型
	int32_t condType = 0;
	if (pDyConditionInfo->totalRate > 0) //根据配置的概率来随机
	{
		if (pDyConditionInfo->vecRate.size() != pDyConditionInfo->vecType.size())
		{
			MMOLOG_FMT_ERROR("[logic] OnGeneralCond pDyConditionInfo->vecRate.size() != pDyConditionInfo->vecType.size()... missionid:%u,condid:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId);
			return RET_FAIL;
		}
		//随机
		int32_t rndNum = Random(pDyConditionInfo->totalRate + 1);//0-totalRate
		int32_t idx = -1;
		int32_t temp = 0;
		int32_t isize = pDyConditionInfo->vecRate.size();
		for (int32_t i = 0; i < isize; ++i)
		{
			temp += pDyConditionInfo->vecRate.at(i);
			if (rndNum <= temp)
			{
				idx = i;
				break;
			}
		}
		if (idx < 0)
		{
			MMOLOG_FMT_ERROR("[logic] OnGeneralCond idx < 0... missionid:%u,condid:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId);
			return RET_FAIL;
		}
		condType = pDyConditionInfo->vecType.at(idx);
	}
	else
	{
		//直接随机
		int32_t rndidx = Random((uint32_t)pDyConditionInfo->vecType.size());
		condType = pDyConditionInfo->vecType.at(rndidx);
	}
	if (!ValidDyCompleteType(condType))
	{
		MMOLOG_FMT_ERROR("[logic] OnGeneralCond ValidDyCompleteType(condType)... missionid:%u,condid:%d,condType:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId, condType);
		return RET_FAIL;
	}
	//阵营参数
	int32_t campType = 0;
	int32_t campParam = MISSION_PARAM_TYPE_MID;
	if (pDyMissionInfo->useCamp) //使用阵营
	{
		if (ECamp_Type_Light == pPlayer->GetCampId())
		{
			campParam = MISSION_PARAM_TYPE_LIGHT;
			campType = ECamp_Type_Light;
		}
		else if (ECamp_Type_Dark == pPlayer->GetCampId())
		{
			campParam = MISSION_PARAM_TYPE_DARK;
			campType = ECamp_Type_Dark;
		}
	}
	else if (MISSION_TYPE_ID_TREASURE == pDyMissionInfo->kind)
	{
		campParam = MISSION_PARAM_TYPE_TREASURE;
	}
	//随机场景
	uint32_t mapId = 0;
	if (pDyConditionInfo->setMap.size() > 0)
	{
		VEC_INT32 vecMap;
		vecMap.clear();
		SET_INT32::const_iterator iterMap = pDyConditionInfo->setMap.begin();
		for (; iterMap != pDyConditionInfo->setMap.end(); ++iterMap)
		{
			uint32_t tmpId = (*iterMap);
			const MapMapCfgInfo *pMapCfgInfo = g_GetMapMapCfgTable()->GetMapMapCfgInfo(tmpId);
			if (nullptr == pMapCfgInfo)
			{
				MMOLOG_FMT_ERROR("OnGeneralCond nullptr == pMapCfgInfo...missionid:%u,condid:%d,condType:%d,mapId:%u ", pDyMissionInfo->missionId, pDyConditionInfo->condId, condType, tmpId)
				continue;
			}
			if ( (ECamp_Type_Light == campType && ECamp_Type_Dark == pMapCfgInfo->mapBias)
				|| (ECamp_Type_Dark == campType && ECamp_Type_Light == pMapCfgInfo->mapBias)
				)
			{
				continue;
			}
			vecMap.push_back((*iterMap));
		}
		if (vecMap.size() <= 0)
		{
			MMOLOG_FMT_ERROR("[logic] OnGeneralCond   vecMap.size() <= 0... missionid:%u,condid:%d,condType:%d, campType:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId, condType, campType);
			return RET_FAIL;
		}
		int32_t idx = Random((uint32_t)vecMap.size());
		mapId = vecMap.at(idx);
		const MapMapCfgInfo *pMapCfgInfo = g_GetMapMapCfgTable()->GetMapMapCfgInfo(mapId);
		if (nullptr == pMapCfgInfo)
		{
			MMOLOG_FMT_ERROR("[logic] OnGeneralCond nullptr == pMapCfgInfo... missionid:%u,condid:%d,condType:%d,mapId:%u,campType:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId, condType, mapId, campType);
			return RET_FAIL;
		}
	}
	

	//根据不同的完成条件类型随机条件参数
	int32_t ret = RET_FAIL;
	if (MISSION_FINISH_TYPE_KILL_MONS == condType)
	{
		ret = OnGeneralKillMonsCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId,campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_KILL_MONS_AREA == condType)
	{
		ret = OnGeneralKillMonsAreaCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_TAKL == condType)
	{
		ret = OnGeneralTalkCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_COLLECT_ITEM == condType)
	{
		ret = OnGeneralCollectItemCond(pPlayer, pDyMissionInfo, pDyConditionInfo, cond);
	}
	else if (MISSION_FINISH_TYPE_COLLECT_MONS == condType)
	{
		ret = OnGeneralCollectMonsCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_COLLECT_CLIENT == condType)
	{
		ret = OnGeneralClientCollectCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_FINISH_ACTION == condType)
	{
		ret = OnGeneralActionButtonCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_USE_THING == condType)
	{
		ret = OnGeneralUseThingCond(pPlayer, pDyMissionInfo, pDyConditionInfo, mapId, campParam, cond);
	}
	else if (MISSION_FINISH_TYPE_SUBMIT_ITEM == condType)
	{
		ret = OnGeneralSubmitItemCond(pPlayer, pDyMissionInfo, pDyConditionInfo, cond);
	}
	else if (MISSION_FINISH_TYPE_SUBMIT_EQUIP == condType)
	{
		ret = OnGeneralSubmitEquipCond(pPlayer, pDyMissionInfo, pDyConditionInfo, cond);
	}
	else
	{
		MMOLOG_FMT_ERROR("[logic] MissionManager::OnGeneralCond...can not find cond type..... missionid:%u,condid:%d,condType:%d,mapId:%u,campType:%d ", pDyMissionInfo->missionId, pDyConditionInfo->condId, condType, mapId, campType);
	}
	if (RET_SUCCESS == ret)
	{
		//随机textid
		textId = GetDyTextId((uint64_t)ComposeTextKey(mapId, pDyMissionInfo->kind, condType, campType));
		if (textId <= 0)
		{
			MMOLOG_FMT_ERROR("[logic] MissionManager::OnGeneralCond...can not find textid..... missionid:%u,condid:%d,mapId:%u,kind:%d, condType:%d,campType:%d", pDyMissionInfo->missionId, pDyConditionInfo->condId, mapId, pDyMissionInfo->kind, condType, campType);
		}
	}

	return ret;
}

//生成杀怪条件
int32_t MissionManager::OnGeneralKillMonsCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*
	MISSION_FINISH_TYPE_KILL_MONS	= 101,		//杀怪			格式 101=怪物id=怪物数量=0=0=0
	生成monterid规则：
	根据任务配置表的“动态任务类型”字段，在monster表中挑选完成场景中所有满足该阵营倾向的parentType=1的monster，从中抽取1个作为目标怪物
	不填或为0则为无阵营倾向，即在monster表内belongToSceneID=完成场景id且parentType=1且dynamictaskType≠0的所有monster中抽取1个monster
	1为光耀阵营倾向，即在monster表内belongToSceneID=完成场景id且parentType=1且dynamictaskType=1的所有monster中抽取1个monster
	2为暗夜阵营倾向，即在monster表内belongToSceneID=完成场景id且parentType=1且dynamictaskType=2的所有monster中抽取1个monster
	*/
	uint32_t monsId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam,1, monsId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//随机怪物数量
	int32_t monsNum = 0;
	int32_t isize = pDyMissionInfo->vecMonsNum.size();
	if (isize > 0)
	{
		int32_t rnd = Random(isize);//0-isize-1
		monsNum = pDyMissionInfo->vecMonsNum.at(rnd);
	}
	if (monsNum <= 0)
	{
		MMOLOG_FMT_WARN("OnGeneralKillMonsCond...monsNum <= 0...cid:%lu, id:%u, condid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, pDyConditionInfo->condId);
	}
	monsNum = (monsNum < 1) ? 1 : monsNum;
	//填充完成条件参数
	cond.type = MISSION_FINISH_TYPE_KILL_MONS;
	cond.itemId = monsId;
	cond.finalValue = monsNum;
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}

//生成杀怪追踪区域
int32_t MissionManager::OnGeneralKillMonsAreaCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	//MISSION_FINISH_TYPE_KILL_MONS_AREA			= 102,		//杀怪追踪区域		格式 102=怪物id=怪物数量=追踪区域id=0=0（仅适用刷出怪物）
	uint32_t areaId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam, 7, areaId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
	if (nullptr == pAreaCfg)
	{
		MMOLOG_FMT_ERROR("OnGeneralKillMonsAreaCond...nullptr == pAreaCfg     cid:%lu,missionid:%u, mapid:%u, areaid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, mapId, areaId);
		return RET_FAIL;
	}
	uint32_t monsId = DyRandNoMapMons(pPlayer->GetCid(), pDyMissionInfo->kind, MISSION_PARAM_TYPE_TREASURE);
	const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
	if (nullptr == pMonsCfg)
	{
		MMOLOG_FMT_ERROR("OnGeneralKillMonsAreaCond...nullptr == pMonsCfg     cid:%lu,missionid:%u, mapid:%u, areaid:%u,monsid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, mapId, areaId, monsId);
		return RET_FAIL;
	}
	//随机怪物数量
	int32_t monsNum = 0;
	int32_t isize = pDyMissionInfo->vecMonsNum.size();
	if (isize > 0)
	{
		int32_t rnd = Random(isize);//0-isize-1
		monsNum = pDyMissionInfo->vecMonsNum.at(rnd);
	}
	if (monsNum <= 0)
	{
		MMOLOG_FMT_WARN("OnGeneralKillMonsAreaCond...monsNum <= 0...cid:%lu, missionid:%u, condid:%u, areaid:%u, monsid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, pDyConditionInfo->condId,areaId,monsId);
	}
	monsNum = (monsNum < 1) ? 1 : monsNum;

	//填充完成条件参数
	cond.type = MISSION_FINISH_TYPE_KILL_MONS_AREA;
	cond.itemId = monsId;
	cond.finalValue = monsNum;
	cond.parma1 = areaId;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}
//生成对话NPC条件
int32_t MissionManager::OnGeneralTalkCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*
	MISSION_FINISH_TYPE_TAKL					= 201,		//对话			格式 201=npcid=1=0=0=0
	生成npcid规则：
	根据任务配置表的“动态任务类型”字段，在npc表中挑选完成场景中所有满足该阵营倾向的npc，从中随机1个作为目标npc
	不填或为0则为无阵营倾向，即在npc表内belongToSceneID=完成场景id且dynamictaskValue≠0的所有npc中抽取1个npc
	1为光耀阵营倾向，即在npc表内belongToSceneID=完成场景id且dynamictaskValue=1的所有npc中抽取1个npc
	2为暗夜阵营倾向，即在npc表内belongToSceneID=完成场景id且dynamictaskValue=2的所有npc中抽取1个npc
	*/

	uint32_t npcId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam,2, npcId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//填充完成条件参数
	cond.type = MISSION_FINISH_TYPE_TAKL;
	cond.itemId = npcId;
	cond.finalValue = 1; //默认1次
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}

//生成收集物品条件 
int32_t MissionManager::OnGeneralCollectItemCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*MISSION_FINISH_TYPE_COLLECT_ITEM			= 301,		//收集物品		格式 301=物品id=物品数量=0=0=0（背包中有足够数量，即完成任务）
	生成itemid规则：
	根据任务配置表的“最低等级”字段，在item表中挑选所有dynamictaskValue =最低等级的item，从中随机1个作为目标物品
	item表新增字段dynamictaskValue：用以区分该item是否用于动态任务及用于哪个等级段，可根据需求扩展。该字段数据填写等级，如20，则在20等级段的任务随机该item
	*/
	uint32_t itemId = 0;
	int32_t nNum = 0;
	int32_t ret = DyRandItemNum(pDyMissionInfo->kind, pDyMissionInfo->minLev, itemId, nNum);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	if (nNum <= 0)
	{
		MMOLOG_FMT_WARN("OnGeneralCollectItemCond...monsNum <= 0...cid:%lu, id:%u, condid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, pDyConditionInfo->condId);
	}
	nNum = (nNum < 1) ? 1 : nNum;

	//填充完成条件参数
	cond.type = MISSION_FINISH_TYPE_COLLECT_ITEM;
	cond.itemId = itemId;
	cond.finalValue = nNum;
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}

//生成前端采集条件
int32_t MissionManager::OnGeneralClientCollectCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*MISSION_FINISH_TYPE_COLLECT_CLIENT			= 304,		//前端采集		格式 304=物品id=物品数量=采集物id=刷新区域id=0
	生成areaid规则：
	根据任务配置表的“动态任务类型”字段，在npc表中挑选完成场景中所有满足该阵营倾向的随机area，从中随机1个作为采集物刷新区域
	不填或为0则为无阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue≠0的所有area中抽取1个area
	1为光耀阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue=1的所有area中抽取1个area
	2为暗夜阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue=2的所有area中抽取1个area
	生成thingid规则：
	根据任务配置表的“动态任务类型”字段，在thing表中挑选所有dynamictaskValue =areaid的随机thing，从中随机1个作为刷新采集物
	生成itemid规则
	根据生成的thingid，查找关联的boxid（thing表drop字段），将box表的item_id字段中填写的itemid作为完成条件307中的目标itemid
	*/
	
	uint32_t areaId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam, 5, areaId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	uint32_t collectThingId = 0;
	ret = DyRandClientCollectThingByArea(areaId, collectThingId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	uint32_t itemId = 0;
	uint32_t paramB = 0;
	ret = DyRandParamByType(2, collectThingId, pDyMissionInfo->kind, itemId, paramB);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//随机物品数量
	int32_t nNum = 0;
	int32_t isize = pDyMissionInfo->vecCollectNum.size();
	if (isize > 0)
	{
		int32_t rnd = Random(isize);//0-isize-1
		nNum = pDyMissionInfo->vecCollectNum.at(rnd);
	}
	if (nNum <= 0)
	{
		MMOLOG_FMT_WARN("OnGeneralClientCollectCond...nNum < 1....cid:%lu , id:%u, condid:%u ",pPlayer->GetCid(),pDyMissionInfo->missionId,pDyConditionInfo->condId)
	}
	nNum = (nNum < 1) ? 1 : nNum;

	//填充完成条件参数 格式 304=物品id=物品数量=采集物id=刷新区域id=0
	cond.type = MISSION_FINISH_TYPE_COLLECT_CLIENT;
	cond.itemId = itemId;
	cond.finalValue = nNum;
	cond.parma1 = collectThingId;
	cond.parma2 = areaId;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}

//生成采集场景物件条件 
int32_t MissionManager::OnGeneralCollectMonsCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}

	/*MISSION_FINISH_TYPE_COLLECT_MONS			= 305,		//采集怪物		格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
	   生成monsterid规则：
	   根据任务配置表的“动态任务类型”字段，在monster表中挑选完成场景中所有满足该阵营倾向的parentType=14的monster，从中抽取1个作为目标怪物
	   不填或为0则为无阵营倾向，即在monster表中belongToSceneID=完成场景id且parentType=14且dynamictaskValue≠0的所有monster中抽取1个monster
	   1为光耀阵营倾向，即在monster表中belongToSceneID=完成场景id且parentType=14且dynamictaskValue=1的所有monster中抽取1个monster
	   2为暗夜阵营倾向，即在完成场景所有belongToSceneID=完成场景id且parentType=14且dynamictaskValue=2的随机monster中抽取1个monster
	   生成boxid规则：
	   根据生成的monsterid，在box表的dynamictaskValue字段查找monsterid
	   将box表的dynamictaskValue=目标monsterid的boxid作为完成条件306中的目标boxid
	   生成itemid规则：
	   根据生成的boxid，将box表的item_id字段中填写的itemid作为完成条件306中的目标itemid
	*/
	uint32_t monsId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam, 3, monsId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	uint32_t itemId = 0;
	uint32_t boxId = 0;
	ret = DyRandParamByType(3, monsId, pDyMissionInfo->kind, itemId, boxId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//随机物品数量
	int32_t nNum = 0;
	int32_t isize = pDyMissionInfo->vecThingNum.size();
	if (isize > 0)
	{
		int32_t rnd = Random(isize);//0-isize-1
		nNum = pDyMissionInfo->vecThingNum.at(rnd);
	}
	if (nNum < 1)
	{
		MMOLOG_FMT_WARN("OnGeneralCollectMons...nNum < 1....cid:%lu , id:%u, condid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, pDyConditionInfo->condId)
	}
	nNum = (nNum < 1) ? 1 : nNum;

	//填充完成条件参数 格式 305=物品id=物品数量=可采集怪物id=宝箱id=0
	cond.type = MISSION_FINISH_TYPE_COLLECT_MONS;
	cond.itemId = itemId;
	cond.finalValue = nNum;
	cond.parma1 = monsId;
	cond.parma2 = boxId;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;
	
	return RET_SUCCESS;
}

//生成 行为按钮条件
int32_t MissionManager::OnGeneralActionButtonCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*
	MISSION_FINISH_TYPE_FINISH_ACTION			= 1001,		//完成行为		格式 1001 = 行为ID = 行为次数 = 行为区域 = 0 = 0

	生成areaid规则：
	根据任务配置表的“动态任务类型”字段，在npc表中挑选完成场景中所有满足该阵营倾向的随机area，从中随机1个作为采集物刷新区域
	不填或为0则为无阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue≠0的所有area中抽取1个area
	1为光耀阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue=1的所有area中抽取1个area
	2为暗夜阵营倾向，即在area表内belongToSceneID=完成场景id且dynamictaskValue=2的所有area中抽取1个area
	生成buttonid规则：
	根据生成的areaid，在button表的dynamictaskValue字段查找areaid。
	将button表的dynamictaskValue=目标areaid的buttonid作为完成条件15中的目标buttonid
	*/
	uint32_t areaId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam, 6, areaId);
	if (RET_SUCCESS != ret)
	{
		return RET_FAIL;
	}
	uint32_t buttonId = 0;
	uint32_t paramB = 0;
	ret = DyRandParamByType(4, areaId, pDyMissionInfo->kind, buttonId, paramB);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//填充完成条件参数 格式 1001 = 行为类型 = 行为ID = 行为区域 = 0 = 0
	cond.type = MISSION_FINISH_TYPE_FINISH_ACTION;
	cond.itemId = buttonId;
	cond.finalValue = 1; //行为次数固定为 1
	cond.parma1 = areaId;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}
//生成 使用场景物件条件
int32_t MissionManager::OnGeneralUseThingCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, uint32_t mapId, int32_t campParam, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/* MISSION_FINISH_TYPE_USE_THING				= 901,		//使用物件		格式 901=怪物id=使用次数=0=0=0
	   生成monsterid规则：
	   根据任务配置表的“动态任务类型”字段，在monster表中挑选完成场景中所有满足该阵营倾向的parentType=15的monster，从中抽取1个作为目标怪物
	   不填或为0则为无阵营倾向，即在monster表中belongToSceneID=完成场景id且parentType=5且dynamictaskValue≠0的所有monster中抽取1个monster
	   1为光耀阵营倾向，即在monster表中belongToSceneID=完成场景id且parentType=5且dynamictaskValue=1的所有monster中抽取1个monster
	   2为暗夜阵营倾向，即在完成场景所有belongToSceneID=完成场景id且parentType=5且dynamictaskValue=2的随机monster中抽取1个monster
	*/
	uint32_t monsId = 0;
	int32_t ret = DyRandMapCampCreature(mapId, campParam, 4, monsId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	//填充完成条件参数 格式 901=怪物id=使用次数=0=0=0
	cond.type = MISSION_FINISH_TYPE_USE_THING;
	cond.itemId = monsId;
	cond.finalValue = 1; //默认1次
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}
//生成 提交物品的条件
int32_t MissionManager::OnGeneralSubmitItemCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*
	MISSION_FINISH_TYPE_SUBMIT_ITEM				= 502,		//提交物品				格式 502=物品id=物品数量=提交npc=0=0

	格式：502=itemid=count=npcid=0=0
	生成itemid规则：
	物品类型：
	根据任务配置表的任务类型字段，在item表中挑选所有dynamictaskType=任务类型的物品。
	物品等级：
	根据任务配置表的“最低等级”字段，在item表中挑选所有dynamictaskLevel =最低等级的item，从中随机1个作为目标物品。
	提交物品npc：根据各任务类型对应的提交方式判断
	如为NPC提交，则交互npcid=提交npcid。
	如为自动提交，则不需要npc
	*/
	uint32_t itemId = 0;
	int32_t nNum = 0;
	int32_t ret = DyRandItemNum(pDyMissionInfo->kind, pDyMissionInfo->minLev, itemId, nNum);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}
	if (nNum < 1)
	{
		MMOLOG_FMT_WARN("OnGeneralSubmitItemCond...nNum < 1....cid:%lu , id:%u, condid:%u ", pPlayer->GetCid(), pDyMissionInfo->missionId, pDyConditionInfo->condId)
	}
	nNum = (nNum < 1) ? 1 : nNum;

	//填充完成条件参数 格式 502=物品id=物品数量=提交npc=0=0
	cond.type = MISSION_FINISH_TYPE_SUBMIT_ITEM;
	cond.itemId = itemId;
	cond.finalValue = nNum; //默认1次
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}
//生成 提交装备的条件
int32_t MissionManager::OnGeneralSubmitEquipCond(Player* pPlayer, const DyMissionInfo *pDyMissionInfo, const DyConditionInfo *pDyConditionInfo, ItemInfo &cond)
{
	if (nullptr == pPlayer || nullptr == pDyMissionInfo || nullptr == pDyConditionInfo)
	{
		return RET_FAIL;
	}
	/*
	MISSION_FINISH_TYPE_SUBMIT_EQUIP			= 503,		//提交装备				格式 503=装备id=装备数量=提交npc=0=0

	格式：305=equipid=count=npcid=0=0
	生成equipid规则：
	根据任务配置表的“最低等级”字段，在equip表中挑选所有dynamictaskValue =最低等级的equip，从中随机1个作为目标装备
	生成npcid规则：
	完成npcid=提交npcid
	*/

	uint32_t itemId = 0;
	int32_t ret = DyRandEquip(pDyMissionInfo->kind, pDyMissionInfo->minLev, pDyMissionInfo->maxLev, itemId);
	if (RET_SUCCESS != ret)
	{
		return ret;
	}

	//填充完成条件参数 格式 503=装备id=装备数量=提交npc=0=0
	cond.type = MISSION_FINISH_TYPE_SUBMIT_EQUIP;
	cond.itemId = itemId;
	cond.finalValue = 1; //默认1个
	cond.parma1 = 0;
	cond.parma2 = 0;
	cond.parma3 = 0;
	cond.currentValue = 0;
	cond.completedFlag = false;

	return RET_SUCCESS;
}


//随机藏宝图怪物
uint32_t MissionManager::DyRandNoMapMons(CharIDType cid,int32_t missionType,  int32_t paramType)
{
	MAP_INT32_SET_UINT32::iterator iter = m_mapNoMapMonsParam.find(paramType);
	if (iter == m_mapNoMapMonsParam.end())
	{
		MMOLOG_FMT_ERROR("DyRandNoMapMons...iter == m_mapNoMapMonsParam.end()   cid:%lu, missionType:%d ,paramType:%d", cid, missionType, paramType);
		return 0;
	}
	SET_UINT32 &setMons = iter->second;
	if (setMons.size() <= 0)
	{
		MMOLOG_FMT_ERROR("DyRandNoMapMons...setMons.size() <= 0    cid:%lu, missionType:%d ,paramType:%d", cid, missionType, paramType);
		return 0;
	}
	uint32_t monsId = 0;
	int32_t rndNum = Random(1, (uint32_t)setMons.size());
	SET_UINT32::iterator iterMon = setMons.begin();
	for (; iterMon != setMons.end(); ++iterMon)
	{
		--rndNum;
		if (rndNum <= 0)
		{
			monsId = (*iterMon);
			break;
		}
	}
	return monsId;	
}
//动态随机地图阵营生物 1-怪物，2-npc,3-可采集物件，4-可使用物件，5-采集物区域，6-行为按钮区域,7-地图区域
int32_t MissionManager::DyRandMapCampCreature(uint32_t mapId, int32_t campParam, int32_t creatureKind, uint32_t &cfgId)
{
	MAP_UINT32_MAP_INT32_SET_UINT32 *pMapCreatureParam = nullptr;
	if (1 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapMonsParam;
	}
	else if (2 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapNpcParam;
	}
	else if (3 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapCollectThingParam;
	}
	else if (4 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapUseThingParam;
	}
	else if (5 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapCollectAreaParam;
	}
	else if (6 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapButtonAreaParam;
	}
	else if (7 == creatureKind)
	{
		pMapCreatureParam = &m_mapMapAreaParam;
	}
	if (nullptr == pMapCreatureParam)
	{
		MMOLOG_FMT_ERROR("DyRandMapCampCreature...nullptr == pMapCreatureParam... mapid:%u, campParam:%d,creatureKind:%d", mapId, campParam, creatureKind);
		return RET_FAIL;
	}

	MAP_UINT32_MAP_INT32_SET_UINT32::iterator iterMap = pMapCreatureParam->find(mapId);
	if (iterMap == pMapCreatureParam->end())
	{
		MMOLOG_FMT_ERROR("DyRandMapCampCreature...iterMap == pMapCreatureParam.end()... mapid:%u, campParam:%d,creatureKind:%d", mapId, campParam, creatureKind);
		return RET_FAIL;
	}
	MAP_INT32_SET_UINT32 &mapCampCreature = iterMap->second;
	SET_UINT32 *pLight = nullptr;
	SET_UINT32 *pMid = nullptr;
	SET_UINT32 *pDark = nullptr;
	SET_UINT32 *pDest = nullptr;
	int32_t dest = 0;
	int32_t totalLight = 0;
	int32_t totalDark = 0;
	int32_t totalMid = 0;
	if (MISSION_PARAM_TYPE_LIGHT == campParam
		|| MISSION_PARAM_TYPE_DARK == campParam
		|| MISSION_PARAM_TYPE_MID == campParam
		)
	{
		MAP_INT32_SET_UINT32::iterator iterA = mapCampCreature.find(MISSION_PARAM_TYPE_LIGHT);
		if (iterA != mapCampCreature.end())
		{
			pLight = &iterA->second;
			totalLight = pLight->size();
		}
		MAP_INT32_SET_UINT32::iterator iterB = mapCampCreature.find(MISSION_PARAM_TYPE_DARK);
		if (iterB != mapCampCreature.end())
		{
			pDark = &iterB->second;
			totalDark = pDark->size();
		}
		MAP_INT32_SET_UINT32::iterator iterC = mapCampCreature.find(MISSION_PARAM_TYPE_MID);
		if (iterC != mapCampCreature.end())
		{
			pMid = &iterC->second;
			totalMid = pMid->size();
		}
	}
	else if (MISSION_PARAM_TYPE_TREASURE == campParam)
	{
		MAP_INT32_SET_UINT32::iterator iterC = mapCampCreature.find(MISSION_PARAM_TYPE_TREASURE);
		if (iterC != mapCampCreature.end())
		{
			pDest = &iterC->second;
			dest = Random(1, (uint32_t)pDest->size());
		}
	}
	
	//如果是中立阵营，从所有的阵营怪里随机一个，如果是黑暗和光明，再对立阵营和中立阵营中随机一个
	if (MISSION_PARAM_TYPE_MID == campParam)
	{
		int32_t totalNum = totalLight + totalDark + totalMid;
		int32_t rndNum = Random(1, totalNum);
		if (rndNum <= totalLight)
		{
			dest = rndNum;
			pDest = pLight;
		}
		else if (rndNum <= (totalLight + totalDark))
		{
			dest = rndNum - totalLight;
			pDest = pDark;
		}
		else
		{
			dest = rndNum - totalLight - totalDark;
			pDest = pMid;
		}
	}
	else if (MISSION_PARAM_TYPE_LIGHT == campParam)
	{
		int32_t totalNum = totalLight + totalMid;
		int32_t rndNum = Random(1, totalNum);
		if (rndNum <= totalLight)
		{
			dest = rndNum;
			pDest = pLight;
		}
		else
		{
			dest = rndNum - totalLight;
			pDest = pMid;
		}
	}
	else if (MISSION_PARAM_TYPE_DARK == campParam)
	{
		int32_t totalNum = totalDark + totalMid;
		int32_t rndNum = Random(1, totalNum);
		if (rndNum <= totalDark)
		{
			dest = rndNum;
			pDest = pDark;
		}
		else
		{
			dest = rndNum - totalDark;
			pDest = pMid;
		}
	}

	if (nullptr == pDest)
	{
		MMOLOG_FMT_ERROR("DyRandMapCampCreature...nullptr == pDest... mapid:%u, campParam:%d,creatureKind:%d, totalLight:%d,totalDark:%d,totalMid:%d", mapId, campParam, creatureKind, totalLight, totalDark, totalMid);
		return RET_FAIL;
	}
	if (dest > (int32_t)pDest->size() || dest <= 0)
	{
		MMOLOG_FMT_ERROR("DyRandMapCampCreature...dest > pDest->size() || dest <= 0... mapid:%u, campParam:%d,creatureKind:%d, dest:%d, dest_size:%d, totalLight:%d,totalDark:%d,totalMid:%d ", mapId, campParam, creatureKind, dest, pDest->size(), totalLight, totalDark, totalMid);
		return RET_FAIL;
	}
	SET_UINT32::iterator iterRes = pDest->begin();
	for (; iterRes != pDest->end(); ++iterRes)
	{
		--dest;
		if (0 == dest)
		{
			cfgId = (*iterRes);
			break;
		}
	}

	return RET_SUCCESS;
}

//根据区域 动态随机采集物ID
int32_t MissionManager::DyRandClientCollectThingByArea(uint32_t areaId, uint32_t &collectThingId)
{
	MAP_UINT32_SET_UINT32::iterator iter = m_mapAreaToClientCollect.find(areaId);
	if (iter == m_mapAreaToClientCollect.end())
	{
		return RET_FAIL;
	}
	SET_UINT32 setCollect = iter->second;
	int32_t isize = setCollect.size();
	if (isize <= 0)
	{
		return RET_FAIL;
	}
	int32_t rndNum = Random(1, isize);
	SET_UINT32::iterator iterCollect = setCollect.begin();
	for (; iterCollect != setCollect.end(); ++iterCollect)
	{
		--rndNum;
		if (rndNum <= 0)
		{
			collectThingId = (*iterCollect);
			break;
		}
	}
	return RET_SUCCESS;
}

//根据任务类型 动态随机物品ID和数量
int32_t MissionManager::DyRandItemNum(int32_t missionType, int32_t level, uint32_t &itemId, int32_t &itemNum)
{
	MAP_INT8_MAP_UINT32_MAP_UINT32_UINT32::iterator iterType = m_mapMissionTypeLevItemNum.find(missionType);
	if (iterType == m_mapMissionTypeLevItemNum.end())
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandItemNum...iterType == m_mapMissionTypeLevItemNum.end()... missiontype:%d,level:%d ", missionType,level);
		return RET_FAIL;
	}
	MAP_UINT32_MAP_UINT32_UINT32 &mapLevItemNum = iterType->second;
	MAP_UINT32_MAP_UINT32_UINT32::iterator iterLev = mapLevItemNum.find(level);
	if (iterLev == mapLevItemNum.end())
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandItemNum...iterLev == mapLevItemNum.end()... missiontype:%d,level:%d ", missionType, level);
		return RET_FAIL;
	}
	MAP_UINT32_UINT32 &mapItemNum = iterLev->second;
	int32_t isize = mapItemNum.size();
	if (isize <= 0)
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandItemNum...mapItemNum.size() <= 0... missiontype:%d,level:%d ", missionType, level);
		return RET_FAIL;
	}
	int32_t rnd = Random(1, isize);
	MAP_UINT32_UINT32::iterator iterItem = mapItemNum.begin();
	for (; iterItem != mapItemNum.end(); ++iterItem)
	{
		--rnd;
		if (rnd <= 0)
		{
			itemId = iterItem->first;
			itemNum = iterItem->second;
			break;
		}
	}
	return RET_SUCCESS;
}

//根据任务类型 动态随机装备ID
int32_t MissionManager::DyRandEquip(int32_t missionType, int32_t minLev,int32_t maxLev,uint32_t &itemId)
{
	SET_UINT32 setEquipRand;
	setEquipRand.clear();
	ORDER_MAP_UINT32_SET_UINT32::iterator iter = m_mapLevEquip.begin();
	for (; iter != m_mapLevEquip.end(); ++iter)
	{
		if (iter->first >= (uint32_t)minLev && iter->first <= (uint32_t)maxLev)
		{
			const SET_UINT32 &setEquip = iter->second;
			SET_UINT32::const_iterator iterEquip = setEquip.begin();
			for (; iterEquip != setEquip.end(); ++iterEquip)
			{
				setEquipRand.insert((*iterEquip));
			}
		}
	}
	int32_t iszie = setEquipRand.size();
	if (iszie <= 0)
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandEquip...iszie <= 0... missiontype:%d,minlev:%d,maxLev:%d ", missionType, minLev,maxLev);
		return RET_FAIL;
	}
	SET_UINT32::iterator iterRes = setEquipRand.begin();
	for (; iterRes != setEquipRand.end();++iterRes)
	{
		--iszie;
		if (iszie <= 0)
		{
			itemId = (*iterRes);
			break;
		}
	}
	return RET_SUCCESS;
}

//根据类型 动态随机参数 type:类型，2-采集物(paramA:物品ID)，3-怪物(paramA:物品ID),4-行为按钮(paramA 按钮ID)   typeVal:类型值
int32_t MissionManager::DyRandParamByType(int32_t type, uint32_t typeKey, int32_t missionType,uint32_t &paramA, uint32_t &paramB)
{
	MAP_UINT32_SET_UINT32 *pMapTypeSetParam = nullptr;
	if (2 == type)
	{
		pMapTypeSetParam = &m_mapCollectToBox;
	}
	else if (3 == type)
	{
		pMapTypeSetParam = &m_mapMonsToBox;
	}
	else if (4 == type)
	{
		pMapTypeSetParam = &m_mapAreaToButton;
	}

	if (nullptr == pMapTypeSetParam)
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandParamByType...nullptr == pMapTypeSetParam...type:%d, typekey:%u, missiontype:%d ", type, typeKey, missionType);
		return RET_FAIL;
	}
	MAP_UINT32_SET_UINT32::iterator iter = pMapTypeSetParam->find(typeKey);
	if (iter == pMapTypeSetParam->end())
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandParamByType...iter == pMapTypeSetParam->end()...type:%d, typekey:%u, missiontype:%d ", type, typeKey, missionType);
		return RET_FAIL;
	}
	SET_UINT32 &setParam = iter->second;
	int32_t isize = setParam.size();
	if (isize <=0 )
	{
		MMOLOG_FMT_ERROR("MissionManager::DyRandParamByType...isize <=0 ...type:%d, typekey:%u, missiontype:%d ", type, typeKey, missionType);
		return RET_FAIL;
	}
	int32_t resId = 0;
	int32_t rndNum = Random(1, isize);
	SET_UINT32::iterator iterRes = setParam.begin();
	for (; iterRes != setParam.end(); ++iterRes)
	{
		--rndNum;
		if (rndNum <= 0)
		{
			resId = (*iterRes);
			break;
		}
	}
	
	if (4 == type) //随机行为按钮ID,结果值保存的就是按钮ID
	{
		paramA = resId;
	}
	else
	{
		//其他类型都是宝箱ID
		paramB = resId;
		const BoxDropCfgInfo *pBoxCfg = g_GetBoxDropCfgTable()->GetBoxDropCfgInfo(paramB);
		if (nullptr == pBoxCfg)
		{
			MMOLOG_FMT_ERROR("DyRandItemByType...nullptr == pBoxCfg...type:%d ,,typeKey:%u,missiontype:%d boxid:%u ", type, typeKey,missionType, paramB);
			return RET_FAIL;
		}
		//取box-drop表中第一个条件的 宝箱子ID
		if (pBoxCfg->vecBoxDropSonCfg.size() < 1)
		{
			MMOLOG_FMT_ERROR("DyRandItemByType...pBoxCfg->vecBoxDropSonCfg.size() < 1...type:%d ,,typeKey:%u,missiontype:%d boxid:%u ", type, typeKey, missionType, paramB);
			return RET_FAIL;
		}
		const BoxDropSonCfgInfo &cfgInfo = pBoxCfg->vecBoxDropSonCfg.at(0);
		const VecSBoxItemGroupCfg *pVecSBoxItemGroupCfg = g_GetDropCfgMgr()->GetBoxItemGroupCfg(cfgInfo.Id);
		if (nullptr != pVecSBoxItemGroupCfg && pVecSBoxItemGroupCfg->size() > 0)
		{
			const SBoxItemGroup &boxGroup = pVecSBoxItemGroupCfg->at(0);
			if (boxGroup.vecBoxItem.size() > 0)
			{
				//取物品列表第一个物品
				paramA = boxGroup.vecBoxItem.at(0).itemId;
			}
		}
	}
	return RET_SUCCESS;
}

//获取任务最大环数
int32_t MissionManager::DyMaxCount(int32_t missionType,int32_t level)
{
	int32_t count = 0;
	const TaskdynamicTaskCfgMap *pTaskDynamicCfg = g_GetTaskdynamicTaskCfgTable()->GetTaskdynamicTaskCfgMap();
	TaskdynamicTaskCfgMap::const_iterator iter = pTaskDynamicCfg->begin();
	for (; iter != pTaskDynamicCfg->end(); ++iter)
	{
		const TaskdynamicTaskCfgInfo &info = iter->second;
		if (missionType == info.taskType && level >= info.minlv && level <= info.maxlv)
		{
			count = info.completeCount;
			break;
		}
	}
	return count;
}
//根据任务类型随机一个任务ID
int32_t MissionManager::DyRandMissionId(Player *pPlayer, int32_t missionType)
{
	if (nullptr == pPlayer)
	{
		return RET_FAIL;
	}
	CharIDType cid = pPlayer->GetCid();
	const SET_UINT32 *pMissionLst = GetDyMissionLstByType(missionType);
	if (nullptr == pMissionLst)
	{
		MMOLOG_FMT_ERROR("DyRandMissionId...nullptr == pMissionLst...missionType:%d ,cid:%lu ", missionType, cid);
		return RET_FAIL;
	}
	uint32_t level = pPlayer->GetAttr(C_LEVEL);
	//获取满足条件的任务ID
	VEC_UINT32 vecMission;
	vecMission.clear();
	SET_UINT32::const_iterator iterSet = pMissionLst->begin();
	for (; iterSet != pMissionLst->end(); ++iterSet)
	{
		const uint32_t missionId = (*iterSet);
		const DyMissionInfo *pDyMissionCfgInfo = GetDyMissionCfgInfo(missionId);
		if (nullptr == pDyMissionCfgInfo || level < pDyMissionCfgInfo->minLev || level > pDyMissionCfgInfo->maxLev)
		{
			continue;
		}
		vecMission.push_back(missionId);
	}
	int32_t iszie = vecMission.size();
	if (iszie <= 0)
	{
		MMOLOG_FMT_ERROR("DyRandMissionId....iszie <= 0....missionType:%d, cid:%lu ", missionType, cid);
		return RET_FAIL;
	}
	int32_t rnd = Random(iszie);
	uint32_t resmissionId = vecMission.at(rnd);
	//
	return resmissionId;
}
//随机任务
int32_t MissionManager::DyRandMissionTrackByType(Player *pPlayer, int32_t missionType, MissionTrack *pMissionTrack)
{
	if (nullptr == pPlayer || nullptr == pMissionTrack)
	{
		return RET_FAIL;
	}
	CharIDType cid = pPlayer->GetCid();
	MissionPart *pMissionPart = dynamic_cast<MissionPart*>(pPlayer->GetPart(PART_MISSION));
	if (nullptr == pMissionPart)
	{
		MMOLOG_FMT_ERROR("DyRandMissionTrackByType...nullptr == pMissionPart...missionType:%d ,cid:%lu ", missionType, cid);
		return RET_FAIL;
	}
	//根据任务类型随机一个任务
	uint32_t resmissionId = DyRandMissionId(pPlayer, missionType);
	const DyMissionInfo *pResDyMissionCfgInfo = GetDyMissionCfgInfo(resmissionId);
	if (nullptr == pResDyMissionCfgInfo)
	{
		MMOLOG_FMT_ERROR("DyRandMissionTrackByType...nullptr == pResDyMissionCfgInfo...missionType:%d, resmissionId:%u ,cid:%lu ", missionType, resmissionId, cid);
		return RET_MISSION_NOT_EXIST;
	}
	uint32_t dymissionId = pMissionPart->AllocNewDyMisssionId();
	if (!pMissionPart->ValidDyMissionId(dymissionId))
	{
		MMOLOG_FMT_ERROR("DyRandMissionTrackByType....dymissionId is invalid....missionType:%d,resmissionId:%u  ,cid:%lu ", missionType, resmissionId,cid);
		return RET_FAIL;
	}
	if (pMissionPart->HaveAccpet(dymissionId))
	{
		MMOLOG_FMT_ERROR("DyRandMissionTrackByType....dymissionId have accept....missionType:%d,resmissionId:%u,dymissionId:%u  ,cid:%lu ", missionType, resmissionId, dymissionId, cid);
		return RET_FAIL;
	}
	//填充完成条件信息 多任务条件
	std::vector<ItemInfo> conds;
	conds.clear();
	uint32_t textId = 0;
	if (RET_SUCCESS != OnExtractDyCond(pPlayer, pResDyMissionCfgInfo, conds, textId,false))
	{
		pMissionPart->FreeDyMissionId(dymissionId);
		MMOLOG_FMT_ERROR(" DyRandMissionTrackByType  resmissionId:%u, cid:%lu , OnExtractCond failed...", resmissionId,cid);
		return RET_FAIL;
	}


	//填充任务数据信息
	pMissionTrack->missionId = resmissionId;
	pMissionTrack->dynamicId = dymissionId;
	pMissionTrack->acceptMissionTime = 0;
	pMissionTrack->status = MISSION_E_ACCEPTABLE;
	pMissionTrack->items = conds;
	pMissionTrack->textId = textId;


	return RET_SUCCESS;
}

//设置任务proto信息
bool MissionManager::SetMissionTrackProto(MissionTrack *pMissionTrack, CharacterDBMissionTrack &missionProto)
{
	if (nullptr == pMissionTrack)
	{
		return false;
	}
	missionProto.set_missionid(pMissionTrack->missionId);
	missionProto.set_dynamicid(pMissionTrack->dynamicId);
	missionProto.set_textid(pMissionTrack->textId);
	missionProto.set_status(pMissionTrack->status);
	missionProto.set_acceptmissiontime(pMissionTrack->acceptMissionTime);
	missionProto.set_ration(pMissionTrack->ration);
	missionProto.set_quality(pMissionTrack->quality);
	for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
	{
		ProtoBuf::CharacterDBMissionItemInfo* pItemInfo = missionProto.add_iteminfo();
		pItemInfo->set_type(pMissionTrack->items[i].type);
		pItemInfo->set_id(pMissionTrack->items[i].itemId);
		pItemInfo->set_currentvalue(pMissionTrack->items[i].currentValue);
		pItemInfo->set_finalvalue(pMissionTrack->items[i].finalValue);
		pItemInfo->set_completedflag(pMissionTrack->items[i].completedFlag);
		pItemInfo->set_parma1(pMissionTrack->items[i].parma1);
		pItemInfo->set_parma2(pMissionTrack->items[i].parma2);
		pItemInfo->set_parma3(pMissionTrack->items[i].parma3);
	}
	MissionDBMoreAttrProto *proto = missionProto.mutable_attr_reward();
	if (nullptr != proto)
	{
		MAP_INT32_INT32::iterator iterAttr = pMissionTrack->mapAttrReward.begin();
		for (; iterAttr != pMissionTrack->mapAttrReward.end(); ++iterAttr)
		{
			MissionDBAttrProto *protoSingle = proto->add_reward();
			if (nullptr != protoSingle)
			{
				protoSingle->set_attrid(iterAttr->first);
				protoSingle->set_attrval(iterAttr->second);
			}
		}
	}
	
	return true;
}

bool MissionManager::SetMissionTrackProto(MissionTrack *pMissionTrack, CMissionTrack &missionProto)
{
	if (nullptr == pMissionTrack)
	{
		return false;
	}
	missionProto.set_missionid(pMissionTrack->missionId);
	missionProto.set_dynamicid(pMissionTrack->dynamicId);
	missionProto.set_textid(pMissionTrack->textId);
	missionProto.set_status(pMissionTrack->status);
	missionProto.set_accepttime(pMissionTrack->acceptMissionTime);
	missionProto.set_ration(pMissionTrack->ration);
	missionProto.set_quality(pMissionTrack->quality);
	for (uint32_t i = 0; i < pMissionTrack->items.size(); i++)
	{
		ProtoBuf::CItemInfo* pItemInfo = missionProto.add_iteminfo();
		pItemInfo->set_type(pMissionTrack->items[i].type);
		pItemInfo->set_id(pMissionTrack->items[i].itemId);
		pItemInfo->set_curvalue(pMissionTrack->items[i].currentValue);
		pItemInfo->set_finvalue(pMissionTrack->items[i].finalValue);
		pItemInfo->set_parma1(pMissionTrack->items[i].parma1);
		pItemInfo->set_parma2(pMissionTrack->items[i].parma2);
		pItemInfo->set_parma3(pMissionTrack->items[i].parma3);
	}
	MissionAllAttrProto *proto = missionProto.mutable_attr_reward();
	if (nullptr != proto)
	{
		MAP_INT32_INT32::iterator iterAttr = pMissionTrack->mapAttrReward.begin();
		for (; iterAttr != pMissionTrack->mapAttrReward.end(); ++iterAttr)
		{
			MissionAttrProto *protoSingle = proto->add_attr();
			if (nullptr != protoSingle)
			{
				protoSingle->set_attrid(iterAttr->first);
				protoSingle->set_attrval(iterAttr->second);
			}
		}
	}
	return true;
}

//从任务proto拷贝信息
bool MissionManager::CopyFromMissionProto(MissionTrack *pMissionTrack, const CharacterDBMissionTrack &missionProto)
{
	if (nullptr == pMissionTrack)
	{
		return false;
	}
	uint32_t missionId = missionProto.missionid();
	uint32_t dynamicId = missionProto.dynamicid();
	uint32_t textId = missionProto.textid();
	pMissionTrack->missionId = missionId;
	pMissionTrack->dynamicId = dynamicId;
	pMissionTrack->textId = textId;
	pMissionTrack->status = missionProto.status();
	pMissionTrack->acceptMissionTime = missionProto.acceptmissiontime();
	pMissionTrack->ration = missionProto.ration();
	pMissionTrack->quality = missionProto.quality();
	for (int32_t j = 0; j < missionProto.iteminfo_size(); j++)
	{
		const ProtoBuf::CharacterDBMissionItemInfo& pItemInfo = missionProto.iteminfo(j);
		ItemInfo itemInfo;
		itemInfo.type = pItemInfo.type();
		itemInfo.itemId = pItemInfo.id();
		itemInfo.currentValue = pItemInfo.currentvalue();
		itemInfo.finalValue = pItemInfo.finalvalue();
		itemInfo.completedFlag = pItemInfo.completedflag();
		itemInfo.parma1 = pItemInfo.parma1();
		itemInfo.parma2 = pItemInfo.parma2();
		itemInfo.parma3 = pItemInfo.parma3();
		pMissionTrack->items.push_back(itemInfo);
	}
	if (missionProto.has_attr_reward())
	{
		const MissionDBMoreAttrProto &allproto = missionProto.attr_reward();
		for (int32_t i = 0; i < allproto.reward_size(); ++i)
		{
			const MissionDBAttrProto &proto = allproto.reward(i);
			pMissionTrack->mapAttrReward[proto.attrid()] = proto.attrval();
		}
	}
	
	return true;
}


//////////////////////////////////////////////////////////////////////////

void MissionManager::AddReward(Player* pPlayer, int32_t kind,TASK_REWARD& reward, float ration)
{
	int32_t unionContri = 0;
	int32_t unionMoney = 0;
	int32_t gold = 0;
	int32_t diamond = 0;
	int32_t binddiamond = 0;
	int32_t killValue = 0;
	MAP_INT32_INT32 mapDeuptyCollect;
	mapDeuptyCollect.clear();
	SItemSourceParam sourceParam;
	sourceParam.source = S_MISSION;
	Part* pIpackage = pPlayer->GetPart(PART_PACKAGE);
	if (nullptr != pIpackage)
	{
		LIST_ITEM addItems;
		for (uint32_t i = 0; i < reward.size(); ++i)
		{
			uint32_t rewardType = reward[i].type;
			uint32_t profression = pPlayer->GetAttr(C_PROF);
			if (reward[i].profession != 0 && profression != reward[i].profession)
			{
				continue;
			}

			if (rewardType == MISSION_AWARD_GOODS || rewardType == MISSION_AWARD_EQUIP) //装备道具奖励 
			{
				SItem item;
				item.nItemID = reward[i].id;
				item.nNum = reward[i].value;
				item.byBind = reward[i].bind;
				addItems.push_back(item);
			}
			else if (rewardType == MISSION_AWARD_ATTR) //属性奖励
			{
				int32_t value = ceil(reward[i].value * ration);
				if (C_EXP == reward[i].id)
				{
					pPlayer->AddExp(value);
				}
				//阵营声望需要特殊处理
				else if (C_CAMP_PRESTIGE == reward[i].id)
				{
					MAP_UINT64_INT32 mapAttr;
					mapAttr[pPlayer->GetCid()] = value;
					g_GetPlayerMgr()->L2C_AddPrestige(mapAttr);
				}
				//工会贡献
				else if (C_UNION_CONTRI == reward[i].id)
				{
					unionContri += value;
				} //工会资金
				else if (C_UNION_MONEY == reward[i].id)
				{
					unionMoney += value;
				}
				else if (C_COLLECT_HERBS == reward[i].id)
				{
					mapDeuptyCollect[ECollectDeputyType_Herbs] += value;
				}
				else if (C_COLLECT_MINE == reward[i].id)
				{
					mapDeuptyCollect[ECollectDeputyType_Mine] += value;
				}
				else if (C_COLLECT_FISH == reward[i].id)
				{
					mapDeuptyCollect[ECollectDeputyType_Fish] += value;
				}
				else if (C_COLLECT_PEEL == reward[i].id)
				{
					mapDeuptyCollect[ECollectDeputyType_Peel] += value;
				}
				else if (C_GOLD == reward[i].id
					|| C_DIAMOND == reward[i].id
					|| C_DIAMOND_BIND == reward[i].id  //金钱相关的调用另外的接口
					)
				{
					pPlayer->AddSourceAttr(reward[i].id, value, true, S_MISSION);
				}
				else if (C_KILLING_VALUE == reward[i].id)
				{
					killValue += value;
				}
				else
				{
					pPlayer->AddAttr(reward[i].id, value, true);
				}
			}
			else if (MISSION_AWARD_RANDOM == rewardType) //随机奖励
			{
				BoxCondCfg boxCond;
				g_GetDropMgr()->GetBoxCond(pPlayer, boxCond);
				g_GetItemMgr()->CreateBoxDropItem(reward[i].id, addItems, gold, diamond, binddiamond, boxCond);
			}
			else if (MISSION_AWARD_UNION_MONEY == rewardType) //工会资金
			{
				unionMoney = (int32_t)reward[i].value;
			}
		}
		pIpackage->AddItem(addItems, sourceParam);
	}
	if (unionContri > 0 || unionMoney > 0)
	{
		LC_UnionUpdateAttrReq req;
		req.set_charid(pPlayer->GetCid());
		req.set_unionmoney(unionMoney);
		req.set_unioncontri(unionContri);
		req.set_source(S_MISSION);
		g_GetLogicService()->SendDataToCenter(EMODULE_ID_UNION, LOGIC_TO_CENTER_UNION_UPDATE_ATTR, &req);
	}
	if (mapDeuptyCollect.size() > 0)
	{
		DeputyPart *pDeputyPart = dynamic_cast<DeputyPart*>(pPlayer->GetPart(PART_DEPUTY));
		if (nullptr != pDeputyPart)
		{
			MAP_INT32_INT32::iterator iterDeuty = mapDeuptyCollect.begin();
			for (; iterDeuty != mapDeuptyCollect.end(); ++iterDeuty)
			{
				pDeputyPart->AddCollectEnergy(iterDeuty->first, iterDeuty->second);
			}
		}
	}
	if (killValue > 0)
	{
		PvpPart *pPvpPart = dynamic_cast<PvpPart*>(pPlayer->GetPart(PART_PVP));
		if (nullptr != pPvpPart)
		{
			pPvpPart->SubPkKillingValue(killValue);
			pPvpPart->SendPvpKillingValue();
		}
	}

	if (gold > 0)
	{
		pPlayer->AddSourceAttr(C_GOLD, gold, true, S_MISSION);
	}
	if (diamond > 0)
	{
		pPlayer->AddSourceAttr(C_DIAMOND, diamond, true, S_MISSION);
	}
	if (binddiamond > 0)
	{
		pPlayer->AddSourceAttr(C_DIAMOND_BIND, binddiamond, true, S_MISSION);
	}
}
bool MissionManager::RemoveReward(Player* pPlayer, TASK_REWARD& reward)
{
	ORDER_MAP_INT32_INT32 costAttrs;
	Part* pIpackage = pPlayer->GetPart(PART_PACKAGE);
	for (uint32_t i = 0; i < reward.size(); ++i)
	{
		uint32_t rewardType = reward[i].type;
		if (rewardType == MISSION_AWARD_GOODS || rewardType == MISSION_AWARD_EQUIP) //道具
		{
			if (nullptr != pIpackage)
			{
				SItemSourceParam sourceParam;
				sourceParam.source = S_MISSION;
				pIpackage->RemoveItem(reward[i].id, reward[i].value, sourceParam, reward[i].bind);
			}			
		}
		else if (rewardType == MISSION_AWARD_ATTR) //属性
		{
			int32_t id = reward[i].id;
			int32_t costValue = -reward[i].value;
			if (C_GOLD == id
				|| C_DIAMOND == id
				|| C_DIAMOND_BIND == id
				)
			{
				pPlayer->AddSourceAttr(id, costValue, true, S_MISSION);
			}
			else
			{
				pPlayer->AddAttr(id, costValue, true);
			}
		}
	}

	return true;
}

uint32_t MissionManager::GetCampBoxId(uint32_t level, uint32_t camp)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetCampBoxId", refRet, level, camp);

	MMO_ASSERT(retCode && refRet.isNumber());

	return refRet.cast<int>();
}

void MissionManager::GetCampMissionNumConfig(int32_t level,int32_t camp,int32_t &blueNum, int32_t &greenNum, int32_t &whiteNum)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		MMOLOG_FMT_ERROR("GetCampMissionNumConfig...nullptr == pScript....");
		return;
	}
	bool retCode = false;
	LuaRef refRet(pScript->GetState());
	retCode = pScript->CallTableFuncRet("Task", "RandCampMissionNumConfig", refRet,level,camp);
	if (!retCode)
	{
		MMOLOG_FMT_ERROR("GetCampMissionNumConfig...CallTableFuncRet return false....level:%d, camp:%d ",level,camp);
		return;
	}
	if (!refRet.isTable())
	{
		MMOLOG_FMT_ERROR("GetCampMissionNumConfig...!refRet.isTable()....level:%d, camp:%d ", level, camp);
		return;
	}
	if (!refRet["mission_quality_blue"].isNumber()
		|| !refRet["mission_quality_green"].isNumber()
		|| !refRet["mission_quality_write"].isNumber()
		)
	{
		MMOLOG_FMT_ERROR("GetCampMissionNumConfig...refRet data type error....level:%d, camp:%d ", level, camp);
		return;
	}
	blueNum = refRet["mission_quality_blue"].cast<int32_t>();
	greenNum = refRet["mission_quality_green"].cast<int32_t>();
	whiteNum = refRet["mission_quality_write"].cast<int32_t>();
}

uint32_t MissionManager::GetCampMissionBaseConfig(std::string parmeter)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetCampMissionBaseConfig", refRet, parmeter);

	if (retCode && refRet.isNil())
	{
		return 0;
	}

	MMO_ASSERT(retCode && refRet.isNumber());

	return refRet.cast<int>();
}

uint32_t MissionManager::GetLoopMissionBaseConfig(std::string parmeter)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetLoopMissionBaseConfig", refRet, parmeter);

	if (retCode && refRet.isNil())
	{
		return 0;
	}

	MMO_ASSERT(retCode && refRet.isNumber());

	return refRet.cast<int>();
}

//获取任务基础奖励
void MissionManager::GetLoopBaseReward(MAP_INT32_INT32 &mapAttrReward, uint32_t loopCount, int64_t level, int64_t upgradeExp)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetLoopBaseReward", refRet, loopCount, level, upgradeExp);
	MMO_ASSERT(retCode && refRet.isTable());

	//
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
}

//获取工会指定环奖励
void MissionManager::GetGuildSpecialReward(uint32_t &boxId, int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildSpecialReward", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return;
	}
	boxId = refRet.cast<uint32_t>();
}

//获取工会日常任务基础奖励
void MissionManager::GetGuildDailyBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level, int32_t officeLev, int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildDailyBaseReward", refRet, level, officeLev, loopCount);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	int32_t exp = refRet["exp"].cast<int32_t>();
	int32_t gold = refRet["gold"].cast<int32_t>();
	int32_t contri = refRet["unionOffer"].cast<int32_t>();
	int32_t unionMoney = refRet["unionMoney"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
	if (contri > 0)
	{
		mapAttrReward[C_UNION_CONTRI] = contri;
	}
	if (unionMoney > 0)
	{
		mapAttrReward[C_UNION_MONEY] = unionMoney;
	}
}
//获取工会日常任务多倍奖励的倍率
int32_t MissionManager::GetGuildDailyRewardMulti(int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildDailyMulti", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return MISSION_RATION_BASE;
	}
	if (!refRet.isNumber())
	{
		return MISSION_RATION_BASE;
	}
	return (refRet.cast<float>() * MISSION_RATION_BASE);
}
//获取工会日常任务随机宝箱奖励
uint32_t MissionManager::GetGuildDailyRandBoxReward(int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildDailyRandReward", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return 0;
	}
	if (!refRet.isNumber())
	{
		return 0;
	}
	return refRet.cast<int32_t>();
}


//获取日常任务基础奖励
void MissionManager::GetDailyBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level, int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetDailyBaseReward", refRet, level, loopCount);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
}
//获取日常任务多倍奖励的倍率
int32_t MissionManager::GetDailyRewardMulti(int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetDailyMulti", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return MISSION_RATION_BASE;
	}
	if (!refRet.isNumber())
	{
		return MISSION_RATION_BASE;
	}
	return (refRet.cast<float>() * MISSION_RATION_BASE);
}
//获取日常任务随机宝箱奖励
uint32_t MissionManager::GetDailyRandBoxReward(int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetDailyRandReward", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return 0;
	}
	if (!refRet.isNumber())
	{
		return 0;
	}
	return refRet.cast<int32_t>();
}

void MissionManager::GetActBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level)//获取活动收集任务基础奖励
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetActBaseReward", refRet, level);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
}

uint32_t MissionManager::GetActRandBoxReward(int32_t loopCount)//获取活动收集任务随机宝箱奖励 
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetActRandReward", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return 0;
	}
	if (!refRet.isNumber())
	{
		return 0;
	}
	return refRet.cast<int32_t>();
}

void MissionManager::GetDeputyBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level,int32_t loopCount,uint32_t itemId)//获取副业任务基础奖励
{
	const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(itemId); 
	if (nullptr == pItemCfg)
	{
		MMOLOG_FMT_ERROR("GetDeputyBaseReward...nullptr == pItemCfg...itemid:%u ", itemId);
		return;
	}
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	int32_t itemLevel = pItemCfg->itemLevel;
	retCode = pScript->CallTableFuncRet("Task", "GetDeputyBaseReward", refRet, level,loopCount, itemLevel);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	int32_t deputy = refRet["deputy"].cast<int32_t>();
	if (deputy > 0)
	{
		if ((int32_t)EItemSubType::EItemSubType_medicinal_materials == pItemCfg->subType)
		{
			mapAttrReward[C_COLLECT_HERBS] = deputy;
		}
		else if ((int32_t)EItemSubType::EItemSubType_mineral == pItemCfg->subType)
		{
			mapAttrReward[C_COLLECT_MINE] = deputy;
		}
		else if ((int32_t)EItemSubType::EItemSubType_fish == pItemCfg->subType)
		{
			mapAttrReward[C_COLLECT_FISH] = deputy;
		}
		else if ((int32_t)EItemSubType::EItemSubType_coat == pItemCfg->subType)
		{
			mapAttrReward[C_COLLECT_PEEL] = deputy;
		}		
	}
	int32_t gold = refRet["gold"].cast<int32_t>();
	int32_t exp = refRet["exp"].cast<int32_t>();

	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
}

int32_t	MissionManager::GetDeputyRewardMulti(int32_t loopCount)//获取副业任务多倍奖励的倍率
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetDeputyMulti", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return MISSION_RATION_BASE;
	}
	if (!refRet.isNumber())
	{
		return MISSION_RATION_BASE;
	}
	return (refRet.cast<float>() * MISSION_RATION_BASE);
}
//获取打图任务基础奖励
void MissionManager::GetTreasureBaseReward(MAP_INT32_INT32 &mapAttrReward)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetTreasureBaseReward", refRet);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
}

void MissionManager::GetTreasureBaseItemReward(uint32_t &itemId, int32_t &num, int8_t &bind)	//获取打图任务基础物品奖励
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetTreasureBaseItemReward", refRet);

	if (retCode && refRet.isNil())
	{
		return;
	}
	if (!refRet.isTable())
	{
		return;
	}
	itemId = refRet["item_id"].cast<uint32_t>();;
	num = refRet["item_num"].cast<int32_t>();
	bind = (int8_t)refRet["bind"].cast<int32_t>();
}

//获取指定环奖励
void MissionManager::GetLoopSpecialReward(uint32_t &boxId, int32_t loopCount)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetLoopSpecialReward", refRet, loopCount);

	if (retCode && refRet.isNil())
	{
		return;
	}
	boxId = refRet.cast<uint32_t>();
}

//获取阵营任务基础奖励
void MissionManager::GetCampBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level, int32_t quality)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetCampBaseReward", refRet,level,quality);

	if (retCode && refRet.isNil())
	{
		return;
	}

	MMO_ASSERT(retCode && refRet.isTable());

	//
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	int32_t prestige = refRet["prestige"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
	if (prestige > 0)
	{
		mapAttrReward[C_CAMP_PRESTIGE] = prestige;
	}
}
//获取赏金任务基础奖励
void MissionManager::GetBountyBaseReward(MAP_INT32_INT32 &mapAttrReward, int32_t level, int32_t quality)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetBountyBaseReward", refRet, level, quality);

	if (retCode && refRet.isNil())
	{
		return;
	}

	MMO_ASSERT(retCode && refRet.isTable());

	//
	int32_t exp = refRet["exp"].cast<int32_t>();;
	int32_t gold = refRet["gold"].cast<int32_t>();
	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
}

uint32_t MissionManager::GetGuildMissionBaseConfig(std::string parmeter)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildMissionBaseConfig", refRet, parmeter);

	if (retCode && refRet.isNil())
	{
		return 0;
	}

	MMO_ASSERT(retCode && refRet.isNumber());

	return refRet.cast<int>();
}

//获取工会任务基础奖励
void MissionManager::GetGuildBaseReward(MAP_INT32_INT32 &mapAttrReward, uint32_t loopCount, int32_t curLevel, int32_t vaultLevel)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetGuildBaseReward", refRet, loopCount, curLevel,vaultLevel);
	MMO_ASSERT(retCode && refRet.isTable());

	int32_t exp = refRet["exp"].cast<int32_t>();
	int32_t gold = refRet["gold"].cast<int32_t>();
	int32_t unionContri = refRet["unionOffer"].cast<int32_t>();
	int32_t unionMoney = refRet["unionMoney"].cast<int32_t>();

	if (exp > 0)
	{
		mapAttrReward[C_EXP] = exp;
	}
	if (gold > 0)
	{
		mapAttrReward[C_GOLD] = gold;
	}
	if (unionContri > 0)
	{
		mapAttrReward[C_UNION_CONTRI] = unionContri;
	}
	if (unionMoney > 0)
	{
		mapAttrReward[C_UNION_MONEY] = unionMoney;
	}
}

uint32_t MissionManager::GetBountyMissionBaseConfig(std::string parmeter)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	MMOLOG_ASSERT(pScript != nullptr);

	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "GetBountyMissionBaseConfig", refRet, parmeter);

	if (retCode && refRet.isNil())
	{
		return 0;
	}

	MMO_ASSERT(retCode && refRet.isNumber());

	return refRet.cast<int>();
}

void MissionManager::GetBountyMissionInfo(bool bFreeFresh, MissionTrack *pMissionTrack, int32_t loopCount)
{
	if (nullptr == pMissionTrack)
	{
		return;
	}
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		MMOLOG_FMT_ERROR("nullptr == pScript");
		return;
	}
	bool retCode = false;
	LuaRef refRet(pScript->GetState());

	retCode = pScript->CallTableFuncRet("Task", "RandomBountyMissionInfo", refRet, bFreeFresh, loopCount);

	if (retCode && refRet.isNil())
	{
		return;
	}

	MMO_ASSERT(retCode && refRet.isTable());

	pMissionTrack->quality = refRet[1].cast<uint32_t>();
	pMissionTrack->ration = (int32_t)(refRet[2].cast<float>() * MISSION_RATION_BASE);
}